Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: what is wrong with my code? need help

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default what is wrong with my code? need help

    yea i have to make a grade calculator that when i run the program it asks me standard questions and i type them into the box and it shows in the bottom (using eclipse btw). So i type stuff in 1 by 1 and basically when i go through it several times its suppose to calculate my gpa but my codes all wrong and stuff. heres what my code says. anyone can help me out or send some insight?


    import javax.swing.JOptionPane;


    public class proj22
    {
    public static void main(String args[]) {
    PrintExplanation();
    name=name();
    semesterValue=semesterValue();
    courseName=courseName();
    courseGrade = courseGrade();
    GetValidNumberInput(courseName, credits, GPA);
    GPA=CalculateGPA(credits, gradeNumber);


    }



    private static String name() {
    // TODO Auto-generated method stub
    return null;
    }



    private static String courseName() {
    // TODO Auto-generated method stub
    return null;
    }



    private static String courseGrade() {
    // TODO Auto-generated method stub
    return null;
    }



    private static String semesterValue() {
    // TODO Auto-generated method stub
    return null;
    }

    int lowerNum=1;
    int upperNum=4;


    static int gradeNumber,credits, GPA, semester;
    static String name, creditsValue, semesterValue, courseName, courseGrade, prompt_user;
    int totalCredits = 0;
    int totalQualityPoints= 0;


    //This explains what the program does and shows it 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 void GetValidNumberInput(String promptStr, int lowerNum, int upperNum){


    String name;
    name= JOptionPane.showInputDialog("Hello, What is your name?");
    System.out.println( "showInputDialog: " + name);

    String semesterValue;
    semesterValue = JOptionPane.showInputDialog("What semester are you in?");
    System.out.println( "showInputDialog: " + semesterValue);



    do {



    String courseName;
    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 courseGrade;
    courseGrade= JOptionPane.showInputDialog("What did you make in this class?");
    System.out.println( "showInputDialog: " + courseGrade);

    String creditsValue;
    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"));



    }




    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 * gradeNumber;
    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")){ gradeNumber = 4;
    }
    else

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

    else

    if
    (grade.equalsIgnoreCase("C")) { gradeNumber = 2;
    }
    else

    if
    (grade.equalsIgnoreCase("D")){
    gradeNumber = 1;
    }

    else
    {
    gradeNumber = 0;
    }
    return
    gradeNumber;

    }
    }


  2. #2
    Junior Member hackthisred's Avatar
    Join Date
    Apr 2012
    Posts
    18
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: what is wrong with my code? need help

    wrap your code in code tags so we can see the code formatted as you would see it in you IDE. But I'd recommend you repost only the section of code that is giving you errors most of your methods have no logic yet, so there really isn't a reason to post it. But you will want to create a VO for your name, courseName, etc, etc; it will be composed of getters and setters and should resemble something like this:
    public class SampleVO {
     
    	String name = null;
    	String courseTitle = null;
    	int grade = 0;
     
    	public String getName() {
    		return name;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
    	public String getCourseTitle() {
    		return courseTitle;
    	}
    	public void setCourseTitle(String courseTitle) {
    		this.courseTitle = courseTitle;
    	}
    	public int getGrade() {
    		return grade;
    	}
    	public void setGrade(int grade) {
    		this.grade = grade;
    	}
     
    }
    f34r th3 kut3 1z

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: what is wrong with my code? need help

    here it is

    import javax.swing.JOptionPane;


    public class proj22
    {
    public static void main(String args[]) {
    PrintExplanation();
    name=name();
    semesterValue=semesterValue();
    courseName=courseName();
    courseGrade = courseGrade();
    GetValidNumberInput(courseName, credits, GPA);
    GPA=CalculateGPA(credits, gradeNumber);


    }



    private static String name() {
    // TODO Auto-generated method stub
    return null;
    }



    private static String courseName() {
    // TODO Auto-generated method stub
    return null;
    }



    private static String courseGrade() {
    // TODO Auto-generated method stub
    return null;
    }



    private static String semesterValue() {
    // TODO Auto-generated method stub
    return null;
    }

    int lowerNum=1;
    int upperNum=4;


    static int gradeNumber,credits, GPA, semester;
    static String name, creditsValue, semesterValue, courseName, courseGrade, prompt_user;
    int totalCredits = 0;
    int totalQualityPoints= 0;


    //This explains what the program does and shows it 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 void GetValidNumberInput(String promptStr, int lowerNum, int upperNum){


    String name;
    name= JOptionPane.showInputDialog("Hello, What is your name?");
    System.out.println( "showInputDialog: " + name);

    String semesterValue;
    semesterValue = JOptionPane.showInputDialog("What semester are you in?");
    System.out.println( "showInputDialog: " + semesterValue);



    do {



    String courseName;
    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 courseGrade;
    courseGrade= JOptionPane.showInputDialog("What did you make in this class?");
    System.out.println( "showInputDialog: " + courseGrade);

    String creditsValue;
    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"));



    }




    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 * gradeNumber;
    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")){ gradeNumber = 4;
    }
    else

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

    else

    if
    (grade.equalsIgnoreCase("C")) { gradeNumber = 2;
    }
    else

    if
    (grade.equalsIgnoreCase("D")){
    gradeNumber = 1;
    }

    else
    {
    gradeNumber = 0;
    }
    return
    gradeNumber;

    }
    }

  4. #4
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: what is wrong with my code? need help

    Quote Originally Posted by balmung123 View Post
    yea i have to make a grade calculator that when i run the program it asks me standard questions and i type them into the box and it shows in the bottom (using eclipse btw). So i type stuff in 1 by 1 and basically when i go through it several times its suppose to calculate my gpa but my codes all wrong and stuff. heres what my code says. anyone can help me out or send some insight?
    Hello balmung123!
    Can you elaborate what's wrong with your code (errors, exceptions, unexpected behaviour)?
    And please edit your post and use the code tags to format it.

Similar Threads

  1. What is wrong with this code?
    By A19 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: August 11th, 2011, 09:45 PM
  2. What's Wrong With My Code?
    By arunjib in forum What's Wrong With My Code?
    Replies: 18
    Last Post: May 7th, 2011, 08:47 PM
  3. what is wrong in this code
    By rk.kavuri in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 6th, 2011, 03:13 PM
  4. What is wrong with my code???
    By nine05 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 8th, 2011, 09:59 AM
  5. What's wrong with my code
    By javapenguin in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 10th, 2010, 03:24 PM