3 Replies - 917 Views - Last Post: 03 October 2012 - 06:13 PM Rate Topic: -----

#1 MataAshita18  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-October 12

Problems with Student.java code and how to test

Posted 03 October 2012 - 05:56 PM

Hi, I'm a Java student who needs some help
The perimeters are of my project are:
Three Instance fields
name - a String of the student's full name
totalQuizScore - double
numQuizesTaken - int
Methods
setName - sets or changes the student name by taking in a parameter
getName - returns the name of the student
getAverageScore - calculates and returns the average quiz score.
addQuiz - takes in a score (int) and adds that score to totalQuizScore and increments the numQuizesTaken field.
getTotalQuizScore - returns the totalQuizScore .
Constructor
Default construtor that sets the instance fields to a default value
Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value.
How would I write a tester for this as well?
I keep getting 14 errors, and when I correct some of them, I get more.
These are the errors
----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

My code so far, Can you tell me what I'm missing?
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("My Name";
	
}


Is This A Good Question/Topic? 0
  • +

Replies To: Problems with Student.java code and how to test

#2 DoinWork  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 69
  • Joined: 26-October 11

Re: Problems with Student.java code and how to test

Posted 03 October 2012 - 06:06 PM

First off, just at first glance, your getters at the bottom are missing the (), and don't put a ; after them. Like line 23...
public string getFullName;



Should be:
public String getFullName()



Plus your toString() is missing a } at the end.
Was This Post Helpful? 2
  • +
  • -

#3 thorax232  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 94
  • Joined: 10-September 12

Re: Problems with Student.java code and how to test

Posted 03 October 2012 - 06:10 PM

Yup, looks like mostly syntax errors. Fix what your console is telling you to fix, to the best of your ability and post back. :) Maybe you'll even fix it all without us.
Was This Post Helpful? 0
  • +
  • -

#4 dimasalang  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 4
  • Joined: 02-October 12

Re: Problems with Student.java code and how to test

Posted 03 October 2012 - 06:13 PM

you've got a lot of errors here.

First: Line 16: I don't know if that's a method or a variable. I think it's a method since you have a return statement at line 17. Lines 16 to 18 should be like this
public int qTaken(){
	return (int) numQuizzesTaken;
	}


all your methods are incorrectly declared. They should be like this:
public String methodName(){
    return "Sample String";
}


Do note that Java is case sensitive.

Also you cannot call the System.out.println outside a method. :bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1