java proj help please

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 518 Views - Last Post: 30 April 2012 - 04:44 PM Rate Topic: -----

#1 portie123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

java proj help please

Posted 25 April 2012 - 02:56 PM

okay well i have a gpa calculator proj i need to do but i cannot get it to run and i ahve no idea what to do now
any help would be appreciated.this is what i have

import javax.swing.JOptionPane;


public class proj22
{
public static void main(String args[]) 
{
}

	static int credits, semester, grades, GPA;
	static String creditsValue, semesterValue, courseName;

public static void PrintExplanation(){
	//This explains what the program is for to the person who is running it.
	JOptionPane.showMessageDialog(null, "This allows you to calculate your GPA for the semster you are/were in by entering the number/letter of your grades).");
	}

public static int GetValidNumberInput(String promptStr, int lowerNum, int upperNum){

	//This gets the course grade and restricts it to within regular GPA limits
	semesterValue = JOptionPane.showInputDialog("What are/were semester are you in?");
	semester = Integer.parseInt(semesterValue);

	do
	{
		courseName = JOptionPane.showInputDialog("What is the course name? \n or type 'end' if no courses left");

	if
	(courseName.equals("end"))

		break;

	System.out.println("showInputDialog: "+ courseName);

	String grade = JOptionPane.showInputDialog("What did you make in this class?");
	System.out.println( "showInputDialog: "+ grade);
	creditsValue = JOptionPane.showInputDialog("How many hours was this class?");
	
	if
	(credits < lowerNum || credits > upperNum){
		JOptionPane.showMessageDialog(null, "That is not a valid number.");
	}

	else
	{
		credits += Integer.parseInt(creditsValue);
	}
}

	while (!courseName.equals("end"));
	return
	credits;
	}


public static void GenerateGPAReport ( int totalCredits, int totalQualityPoints){
	//This shows what the GPA is
	JOptionPane.showMessageDialog(null,"Grading Period:"+semester+ "\n Total Credits Taken :"+totalCredits+ "\n Total Quality Points:"+totalQualityPoints+"\n GPA:"+GPA);
	}

public static int CalculateGPA (int totalCredits, int totalQualityPoints){
	//Calculates the GPA
	totalQualityPoints = credits * grades;
	GPA = totalQualityPoints / totalCredits;
	return GPA;
	}

public static int ConvertGradeToPoints(String grade){
	//This converts their letter grade to a GPA number grade(i.e. A = 4, B=3, C=2, ect)
	if (grade.equalsIgnoreCase("A")){ grades = 4;
	}
	else

	if
	(grade.equalsIgnoreCase("B")){
		grades = 3;
	}

	else

	if
	(grade.equalsIgnoreCase("C")) { grades = 2;
	}
	else 
		
		if
		(grade.equalsIgnoreCase("D")){
			grades = 1;
		}

		else
		{
			grades = 0;
		}
	return
grades;

	}

}



Is This A Good Question/Topic? 0
  • +

Replies To: java proj help please

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1980
  • View blog
  • Posts: 4,824
  • Joined: 10-September 10

Re: java proj help please

Posted 25 April 2012 - 02:59 PM

Why is the main() method empty? It's the only method that runs when the program begins. The other methods have to be called into action.
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 6460
  • View blog
  • Posts: 23,489
  • Joined: 12-June 08

Re: java proj help please

Posted 25 April 2012 - 03:00 PM

Are you sure you just didn't copy/paste the code from here?
Was This Post Helpful? 0
  • +
  • -

#4 portie123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Re: java proj help please

Posted 25 April 2012 - 03:02 PM

yea i asked my professor that can you help me with the main method he didnt say anything useful so do i post it umm.. like this then?


import javax.swing.JOptionPane;


public class proj22
{
public static void main(String args[]) 
{


	static int credits, semester, grades, GPA;
	static String creditsValue, semesterValue, courseName;
}

public static void PrintExplanation(){
	//This explains what the program is for to the person who is running it.
	JOptionPane.showMessageDialog(null, "This allows you to calculate your GPA for the semster you are/were in by entering the number/letter of your grades).");
	}

public static int GetValidNumberInput(String promptStr, int lowerNum, int upperNum){

	//This gets the course grade and restricts it to within regular GPA limits
	semesterValue = JOptionPane.showInputDialog("What are/were semester are you in?");
	semester = Integer.parseInt(semesterValue);

	do
	{
		courseName = JOptionPane.showInputDialog("What is the course name? \n or type 'end' if no courses left");

	if
	(courseName.equals("end"))

		break;

	System.out.println("showInputDialog: "+ courseName);

	String grade = JOptionPane.showInputDialog("What did you make in this class?");
	System.out.println( "showInputDialog: "+ grade);
	creditsValue = JOptionPane.showInputDialog("How many hours was this class?");
	
	if
	(credits < lowerNum || credits > upperNum){
		JOptionPane.showMessageDialog(null, "That is not a valid number.");
	}

	else
	{
		credits += Integer.parseInt(creditsValue);
	}
}

	while (!courseName.equals("end"));
	return
	credits;
	}


public static void GenerateGPAReport ( int totalCredits, int totalQualityPoints){
	//This shows what the GPA is
	JOptionPane.showMessageDialog(null,"Grading Period:"+semester+ "\n Total Credits Taken :"+totalCredits+ "\n Total Quality Points:"+totalQualityPoints+"\n GPA:"+GPA);
	}

public static int CalculateGPA (int totalCredits, int totalQualityPoints){
	//Calculates the GPA
	totalQualityPoints = credits * grades;
	GPA = totalQualityPoints / totalCredits;
	return GPA;
	}

public static int ConvertGradeToPoints(String grade){
	//This converts their letter grade to a GPA number grade(i.e. A = 4, B=3, C=2, ect)
	if (grade.equalsIgnoreCase("A")){ grades = 4;
	}
	else

	if
	(grade.equalsIgnoreCase("B")){
		grades = 3;
	}

	else

	if
	(grade.equalsIgnoreCase("C")) { grades = 2;
	}
	else 
		
		if
		(grade.equalsIgnoreCase("D")){
			grades = 1;
		}

		else
		{
			grades = 0;
		}
	return
grades;

	}

}


Was This Post Helpful? 0
  • +
  • -

#5 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1980
  • View blog
  • Posts: 4,824
  • Joined: 10-September 10

Re: java proj help please

Posted 25 April 2012 - 03:04 PM

We can help you with code you've written. Why don't you post some?
Was This Post Helpful? 0
  • +
  • -

#6 portie123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Re: java proj help please

Posted 25 April 2012 - 03:04 PM

well i used parts from there but i didnt know what the other stuff meant but the main codes were the same as most of my main codes
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8022
  • View blog
  • Posts: 31,133
  • Joined: 06-March 08

Re: java proj help please

Posted 25 April 2012 - 08:09 PM

I doubt, you can't define static variables in a method main() or not
Was This Post Helpful? 0
  • +
  • -

#8 portie123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Re: java proj help please

Posted 25 April 2012 - 08:40 PM

well i worked on my code some and this is what i have but do not have an idea on what to do now

import javax.swing.JOptionPane;


public class proj22
{
public static void main(String args[]) {
	PrintExplanation();
	name();
    semesterValue();
    courseName();
    courseGrade();
    
    

    
    
    



}


	
	static int credits, semester, grades, GPA;
	static String name, creditsValue, semesterValue, courseName, courseGrade;


	
	//This explains what the program is for to the person who is running it.
	public static void PrintExplanation(){
	
	JOptionPane.showMessageDialog(null, "This allows you to calculate your GPA for the semster you are/were in by entering the number/letter of your grades).");
	}

	public static String name(){
    String Name;
    Name = JOptionPane.showInputDialog("So, What is your name?");

    return Name;
	}
	
	public static String semesterValue(){
        String semester;

        semester = JOptionPane.showInputDialog("What semester are you currently in?");

        return semester;
	}
	
	
	 public static String courseName(){
         String course;

         course = JOptionPane.showInputDialog("What class are you currently in?");

         return course;

    }
	 
	
	 public static String courseGrade(){
         String grade;

         grade = JOptionPane.showInputDialog(",What grade did you get in this class?");

         return grade;

  }
	

public static int GetValidNumberInput(String promptStr, int lowerNum, int upperNum){

	int credits;
	 
    
	do{

    credits = Integer.parseInt(JOptionPane.showInputDialog(promptStr));

               }while(credits < lowerNum || credits > upperNum);

    return credits;
	}


public static void GenerateGPAReport ( int totalCredits, int totalQualityPoints){
	//This shows what the GPA is
	JOptionPane.showMessageDialog(null,"Grading Period:"+semester+ "\n Total Credits Taken :"+totalCredits+ "\n Total Quality Points:"+totalQualityPoints+"\n GPA:"+GPA);
	}

public static int CalculateGPA (int totalCredits, int totalQualityPoints){
	//Calculates the GPA
	totalQualityPoints = credits * grades;
	GPA = totalQualityPoints / totalCredits;
	return GPA;
	}

public static int ConvertGradeToPoints(String grade){
	//This converts the grades inputed to a number (i.e. A = 4, B=3, C=2, ect)
	;
	
	if (grade.equalsIgnoreCase("A")){ grades = 4;
	}
	else

	if
	(grade.equalsIgnoreCase("B")){
		grades = 3;
	}

	else

	if
	(grade.equalsIgnoreCase("C")) { grades = 2;
	}
	else 
		
		if
		(grade.equalsIgnoreCase("D")){
			grades = 1;
		}

		else
		{
			grades = 0;
		}
	return
grades;

	    }
	}



Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8022
  • View blog
  • Posts: 31,133
  • Joined: 06-March 08

Re: java proj help please

Posted 25 April 2012 - 09:04 PM

Methods


    name();
    semesterValue();
    courseName();
    courseGrade();


return a String value. You don't store that String anywhere. Something like:

name = name();
...
Was This Post Helpful? 0
  • +
  • -

#10 portie123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Re: java proj help please

Posted 25 April 2012 - 09:22 PM

hmm i got little bit more done, but i get this now

import javax.swing.JOptionPane;


public class proj22
{
public static void main(String args[]) {
	PrintExplanation();
	name=name();
    semesterValue=semesterValue();
    courseName = courseName();
    courseGrade = courseGrade();
    GetValidNumberInput("How many credit Hours is the class Worth?" ,1,4);
    ConvertGradeToPoints(courseGrade);
    CalculateGPA(credits, grades);
 
    

    
    
    



}


	
	static int credits, semester, grades, GPA;
	static String name, creditsValue, semesterValue, courseName, courseGrade;


	
	//This explains what the program is for to the person who is running it.
	public static void PrintExplanation(){
	
	JOptionPane.showMessageDialog(null, "This allows you to calculate your GPA for the semster you are/were in by entering the number/letter of your grades).");
	}

	public static String name(){
    String Name;
    Name = JOptionPane.showInputDialog("So, What is your name?");

    return Name;
	}
	
	public static String semesterValue(){
        String semester;

        semester = JOptionPane.showInputDialog("What semester are you currently in?");

        return semester;
	}
	
	
	 public static String courseName(){
         String course;

         course = JOptionPane.showInputDialog("What class are you currently in?");

         return course;

    }
	 
	
	 public static String courseGrade(){
         String grade;

         grade = JOptionPane.showInputDialog(",What grade did you get in this class?");

         return grade;

  }
	

public static int GetValidNumberInput(String promptStr, int lowerNum, int upperNum){

	int credits;
	 
    
	do{

    credits = Integer.parseInt(JOptionPane.showInputDialog(promptStr));

               }while(credits < lowerNum || credits > upperNum);

    return credits;
	}


public static void GenerateGPAReport ( int totalCredits, int totalQualityPoints){
	//This shows what the GPA is
	JOptionPane.showMessageDialog(null,"Grading Period:"+semester+ "\n Total Credits Taken :"+totalCredits+ "\n Total Quality Points:"+totalQualityPoints+"\n GPA:"+GPA);
	}

public static int CalculateGPA (int totalCredits, int totalQualityPoints){
	//Calculates the GPA
	totalQualityPoints = credits * grades;
	GPA = totalQualityPoints / totalCredits;
	return GPA;
	}

public static int ConvertGradeToPoints(String grade){
	//This converts the grades inputed to a number (i.e. A = 4, B=3, C=2, ect)
	;
	
	if (grade.equalsIgnoreCase("A")){ grades = 4;
	}
	else

	if
	(grade.equalsIgnoreCase("B")){
		grades = 3;
	}

	else

	if
	(grade.equalsIgnoreCase("C")) { grades = 2;
	}
	else 
		
		if
		(grade.equalsIgnoreCase("D")){
			grades = 1;
		}

		else
		{
			grades = 0;
		}
	return
grades;

	    }
	}





and get this error "Exception in thread "main" java.lang.ArithmeticException: / by zero
at proj22.CalculateGPA(proj22.java:98)
at proj22.main(proj22.java:14)"
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8022
  • View blog
  • Posts: 31,133
  • Joined: 06-March 08

Re: java proj help please

Posted 25 April 2012 - 09:58 PM

Where did you store the value returned by

GetValidNumberInput("How many credit Hours is the class Worth?" ,1,4);
Was This Post Helpful? 0
  • +
  • -

#12 portie123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Re: java proj help please

Posted 25 April 2012 - 10:00 PM

i think it was suppose to be line 75 but is it suuppse to be the same thing?
Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8022
  • View blog
  • Posts: 31,133
  • Joined: 06-March 08

Re: java proj help please

Posted 25 April 2012 - 10:06 PM

credits = GetValidNumberInput("How many credit Hours is the class Worth?" ,1,4);

then your value of credits won't be 0 as it is right now has you haven't store the value returned by the method

same thing as for name, courseName, grade, ....
Was This Post Helpful? 0
  • +
  • -

#14 portie123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Re: java proj help please

Posted 25 April 2012 - 10:10 PM

yea i have no idea i guess ill just have to turn in what i got
Was This Post Helpful? 0
  • +
  • -

#15 portie123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Re: java proj help please

Posted 26 April 2012 - 12:02 AM

okay i couldnt find the edit button so im going to have to double post but i did some more work and its coming out a bit better but i had a question how do i in my code make it post multiple prompts for classes like how do i make it ask multiple "name of the class then after that name of the other class" or something to that kind of effect?


import javax.swing.JOptionPane;


public class proj22
{
public static void main(String args[]) {
	PrintExplanation();
	name=name();
    semester=semesterValue();
    courseName = courseName();
  //  courseGrade = courseGrade();
  //  GetValidNumberInput(credits);
   // GPA=CalculateGPA(credits, grades);
		
    
    
    
    
	JOptionPane.showMessageDialog(null, name);
	//JOptionPane.showMessageDialog(null, courseName + "  " + semester + courseGrade + credits);
	
	
	//JOptionPane.showMessageDialog(null,"Grading Period:"+semester+ "\n Total Credits Taken :"+ totalCredits + "\n Total Quality Points:"+ totalQualityPoints + "\n GPA:"+ GPA);


			


    
    
    



}


	
	static int grades, GPA;
	static String name, creditsValue, semesterValue, courseName, courseGrade, credits, semester, totalCredits, totalQualityPoints;


	
	//This explains what the program is for to the person who is running it.
	public static void PrintExplanation(){
	
	JOptionPane.showMessageDialog(null, "This allows you to calculate your GPA for the semster you are/were in by entering the number/letter of your grades).");
	}

	public static String name(){
    String Name;
    Name = JOptionPane.showInputDialog("So, What is your name?");

    return Name;
	}
	
	public static String semesterValue(){
        String semester;

        semester = JOptionPane.showInputDialog("What semester are you currently in?");

        return semester;
	}
	
	
	 public static String courseName(){
         String course;

         course = JOptionPane.showInputDialog("What classes are you currently in?");

         return course;

    }
	 
	
	 public static String courseGrade(){
         String grade;

         grade = JOptionPane.showInputDialog(",What grade did you get in this class?");

         return grade;

  }


public static int GetValidNumberInput(String promptStr, int lowerNum, int upperNum){

			lowerNum=1;
			upperNum=4;
			promptStr=("How many credits is the class:"+ courseName +"?");
			
			String validInput;
			int value;
			do{
				
				validInput=JOptionPane.showInputDialog(promptStr);
				value=Integer.parseInt(validInput);
			}
				
				while(value<lowerNum&value>upperNum);
				
				return value;  



	}


public static void GenerateGPAReport ( int totalCredits, int totalQualityPoints){
	//This shows what the GPA is
	JOptionPane.showMessageDialog(null,"Grading Period:"+semester+ "\n Total Credits Taken :"+totalCredits+ "\n Total Quality Points:"+totalQualityPoints+"\n GPA:"+GPA);
	}

public static int CalculateGPA (int totalCredits, int totalQualityPoints){
	//Calculates the GPA
	totalQualityPoints = (credits *grades);
	GPA = totalQualityPoints / totalCredits;
	return GPA;
	}

public static int ConvertGradeToPoints(String grade){
	//This converts the grades inputed to a number (i.e. A = 4, B=3, C=2, ect)
	;
	
	if (grade.equalsIgnoreCase("A")){ grades = 4;
	}
	else

	if
	(grade.equalsIgnoreCase("B")){
		grades = 3;
	}

	else

	if
	(grade.equalsIgnoreCase("C")) { grades = 2;
	}
	else 
		
		if
		(grade.equalsIgnoreCase("D")){
			grades = 1;
		}

		else
		{
			grades = 0;
		}
	return
grades;

	    }
	}



Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2