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: Can't find the solution to errors in code

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can't find the solution to errors in code

    Here is the problem from the book:

    "Write a class that uses a string array or arraylist object to hold 5 students names, an array of 5 chars to hold 5 students letter grades, and five array of 4 doubles each to hold each students set of test scores. The class should have methods that return a specific students name, average test score, and a letter grade based on the average.

    Demonstrate the class in a program that allows the user to enter each student's name and his four test scores. It should display each students average test score and letter grade."

    Here is the code I have so far. A buddy and I wrote this together but we cant seem to fix the syntax errors. Any help is appreciated.

    PHP Code:
    public class CST150KLHW8gradeBook {

        
    /**
         * @param args the command line arguments
         */
        
    public static void main(String[] args) {
            
    // TODO code application logic here
        
    }
     private final 
    int NUM_STUDENTS 5;// Holds number of students
     
    private final int NUM_TESTS 4;// Holds number of tests
     
    private String[] names = new String[NUM_STUDENTS]; //Holds students names
     
    private char[] grades = new char[NUM_STUDENTS]; // Holds grades
     
    private double[] scores1 = new double[NUM_TESTS];// Holds score for first test
     
    private double[] scores2 = new double[NUM_TESTS];//Holds score for second test
     
    private double[] scores3 = new double[NUM_TESTS];//Holds score for third test
     
    private double[] scores4 = new double[NUM_TESTS];//Holds score for fourth test
     
    private double[] scores5 = new double[NUM_TESTS];// Holds score for fifth test
     
    public String getName()// Gets students names
     
    public String getTestavg()//Gets the test average
     
    public String getGrade()//Gets the letter grade
     
    {
     public 
    void setName(String n)
    {
    name =  n;
    }
     public 
    String getName()
             return 
    name;
    }
    public 
    void setTest(double t,int i)
    {
    test[i] = t
    }
    public 
    double getTest(int i
    {
    return 
    test[i]; 
    }
    public 
    double getTestAvg(){  
     
    double sum 0;  
    double avg;  
    for(
    int i 0test.lengthi++)  
    {  
    sum += test[i];  
    }  
    avg sum test.length;  
    return 
    avg;  
    }  
    public 
    char getGrade(){  
    double average getTestAvg();  
    char grade=0;  
    if(
    average >= 90)  
    grade 'A';  
    else if (
    average >= 80)  
    grade 'B';  
    else if (
    average >= 70)
    grade 'C';  
    else if (
    average >=60)  
    grade 'D';  
    else if (
    average 60)  
    grade 'F';  
    return 
    grade;  



  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Can't find the solution to errors in code

    please paste the error

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

    Default Re: Can't find the solution to errors in code

    public String getName()// Gets students names
    public String getTestavg()//Gets the test average
    public String getGrade()//Gets the letter grade

    i get an syntax error about missing method body and ; expected

  4. #4
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Can't find the solution to errors in code

    Quote Originally Posted by ahuang1031 View Post
    public String getName()// Gets students names
    public String getTestavg()//Gets the test average
    public String getGrade()//Gets the letter grade

    i get an syntax error about missing method body and ; expected
    you cannot name a variable with parenthesis.
    please read this Variables (The Java™ Tutorials > Learning the Java Language > Language Basics)
    each statement in java must end with semicolon otherwise you'll get a compilation error

Similar Threads

  1. [SOLVED] ALGORITHM TO USE TO FIND A SOLUTION TO A POINT GAME
    By Tjones787 in forum Algorithms & Recursion
    Replies: 4
    Last Post: January 20th, 2014, 04:18 PM
  2. Cannot find symbol errors
    By UM68 in forum Object Oriented Programming
    Replies: 9
    Last Post: September 26th, 2013, 02:41 PM
  3. Program errors because it cannot find something it shouldnt be looking for
    By CrazyCrinkle in forum Object Oriented Programming
    Replies: 3
    Last Post: July 3rd, 2013, 01:11 PM
  4. Java Program Help! Cant find errors
    By frenchsasha in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 6th, 2013, 10:30 AM
  5. [SOLVED] Can't find solution for error in my code..
    By adi2609 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 26th, 2013, 11:10 AM