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 5 of 5

Thread: My Class assignment help

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

    Default My Class assignment help

    Hi, I need help with a code for class, and a tester for it
    so far the error messages continue
    ----jGRASP exec: javac -g Student.java

    Student.java:17: error: illegal start of type
    return (int); numQuizzesTaken;
    ^
    Student.java:17: error: <identifier> expected
    return (int); numQuizzesTaken;
    ^
    Student.java:17: error: <identifier> expected
    return (int); numQuizzesTaken;
    ^
    Student.java:19: error: class, interface, or enum expected
    public string toString() {
    ^
    Student.java:23: error: class, interface, or enum expected
    public string getFullName;
    ^
    Student.java:24: error: class, interface, or enum expected
    {
    ^
    Student.java:26: error: class, interface, or enum expected
    }
    ^
    Student.java:27: error: class, interface, or enum expected
    public double getTotalQuizScore;
    ^
    Student.java:28: error: class, interface, or enum expected
    {
    ^
    Student.java:30: error: class, interface, or enum expected
    }
    ^
    Student.java:31: error: class, interface, or enum expected
    public int getNumQuizzesTaken;
    ^
    Student.java:32: error: class, interface, or enum expected
    {
    ^
    Student.java:34: error: class, interface, or enum expected
    }
    ^
    Student.java:38: error: class, interface, or enum expected
    }
    ^
    14 errors
    and here's my code:
    public class Student
    {
     
    	private String fullName;
    	private int totalQuizScore;
    	private int numQuizzesTaken;
     
    	public Student(String lname, int qScore, int qTaken) {
    	this.fullName = Name;
    	this.totalQuizScore = qScore;
    	this.numQuizzesTaken = qTaken;
    	}
    	public double qScore () {
    	return (double) totalQuizScore / (int) numQuizzesTaken;
    	}
    	public int qTaken;
    	return (int); numQuizzesTaken;
    	}
    	public string toString() {
    	return getFullName() + ", " + getTotalQuizScore() + ", " + getNumQuizzesTaken();
     
    	/*getters*/
    	public string getFullName; 
    	{
    	return fullName;
    	}
    	public double getTotalQuizScore; 
    	{
    	return totalQuizScore;
    	}
    	public int getNumQuizzesTaken; 
    	{
    	return numQuizzesTaken;
    	}
     
    	System.out.println("Ben Scanlan";
     
    }
    What do I need to do to fix and write a tester for this. Please answer soon, it's due Sunday
    Thank you so much


  2. #2
    Member
    Join Date
    Jun 2012
    Posts
    105
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: My Class assignment help

    Do you mind if you actually post the assignment.

    Thanks

  3. #3
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: My Class assignment help

    Have a close look at this line:

    return (int); numQuizzesTaken;

    See anything out of place?

    As an aside, why are you casting an int to an int? Isn't that bit redundant and repetitive?

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    21
    My Mood
    Confused
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: My Class assignment help

    Your coding is a little hard to read.... I see your constructor and accessor methods, but where are you mutator methods?
    this makes no sense:
    public double qScore () {
    return (double) totalQuizScore / (int) numQuizzesTaken;
    }
    public int qTaken;
    return (int); numQuizzesTaken;
    }
    in terms of data types I'm talking about and (double), (int) is not needed...

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: My Class assignment help

    Please use [code=java] before your code and [/code] after your code to keep the formatting and make pretty colors.



    What is Name supposed to be in the constructor? Perhaps you meant lname?


    In the line:
    return (double) totalQuizScore / (int) numQuizzesTaken;
    ...specifying (double) is useful in getting the correct average but the use of (int) on an int is unnecessary


    In the line:
    public int qTaken;
    ...the method's syntax is incorrect. Here is a basic template for a method followed by an example you can look at. 4 of the methods in the posted code have the same problem.
    accessModifier returnType methodName(param1Type param1Name, param2Type param2Name) {
       param1Name someWorkWith param2Name
       return valueOfReturnType;
    }
    /** Returns the result of multiplying the factors, a fairly useless method commonly used as an example.
    *@param factor1 The first factor to be multiplied.
    *@param factor2 The second factor to be multiplied.
    *@return The result of multiplying factor1 and factor2.
    */
    public static int productOf(int factor1, int factor2) {
       int result = 0;
       result = factor1 * factor2;
       return result;
       //return factor1 * factor2;  //shorthand version
    }



    string is not the same as String in java source code.



    There is a closing bracket missing from the end of the toString method



    The line:
    System.out.println("Ben Scanlan";
    ...seems to be missing something

Similar Threads

  1. class assignment
    By shanem in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 2nd, 2012, 01:23 PM
  2. class assignment
    By shanem in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 2nd, 2012, 01:23 PM
  3. Help with class assignment !
    By Ryoshiro in forum What's Wrong With My Code?
    Replies: 13
    Last Post: October 1st, 2012, 09:35 PM
  4. class assignment
    By shanem in forum Java Theory & Questions
    Replies: 1
    Last Post: October 1st, 2012, 04:09 PM
  5. Instrument Class Assignment Help
    By kinney.j in forum Object Oriented Programming
    Replies: 1
    Last Post: November 2nd, 2011, 07:27 AM