View Single Post
  #4 (permalink)  
Old 07-27-2007, 02:16 PM
nitinborge5 nitinborge5 is offline
Member
 
Join Date: Jul 2007
Posts: 10
nitinborge5 is on a distinguished road
Quote:
Originally Posted by toby View Post
Hi, I have a program but I am having a problem getting it to run (it compiled fine).
Its error is that there is no class definition found. I really don't know what that means or how to fix it.
Any one know? and also I'm not sure if I saved it under the right name I saved it under Student.java, is this right?

Code:
class Student { private String firstName; private String lastName; private Address homeAddress; private Address schoolAddress; private int test1; private int test2; private int test3; public Student (String first, String last, Address home, Address school) { lastName=last; firstName=first; homeAddress=home; schoolAddress=school; test1=0; test2=0; test3=0; } public void setTestScore (int testNumber, int testScore) { if (testNumber == 1) test1 = testScore; else if (testNumber == 2) test2 = testScore; else test3 = testScore; } public int getTestScore(int testNumber) { if (testNumber == 1) return test1; else if (testNumber == 2) return test2; else return test3; } public double getAverage() { return (test1 + test2 + test3)/3; } public String toString() { String result = firstName +"\n"+ lastName +"\n"+ "HomeAddress: "+ homeAddress + "\n"+ "schoolAddress: "+ schoolAddress + "\n"+ "test1: " + "test 1" + "\n"+ "test2: " + "test 2" + "\n"+ "test3: " + "test 3" + "\n"+ "average: " +this.getAverage()+"\n"; return result; } } class Course { static int numberStudent = 0; String title; Student student1; Student student2; Student student3; Student student4; Student student5; public Course(String courseTitle) { title=courseTitle; } public void addStudent(String first, String last, Address home, Address school) { switch(numberStudent) { case 0: student1 = new Student(first,last,home,school); case 1: student2 = new Student(first,last,home,school);break; case 2: student3 = new Student(first,last,home,school);break; case 3: student4 = new Student(first,last,home,school);break; case 4: student5 = new Student(first,last,home,school);break; default: System.out.println("No More students allowed in the class"); } numberStudent++; } public String toString() { String results=""; results += student1.toString () +"n"; results += student2.toString () +"n"; results += student3.toString () +"n"; results += student4.toString () +"n"; results += student5.toString () +"n"; return results; } class Address { private String streetAddress; private String city; private String state; private long zipCode; public Address(String stAddress,String cityValue,String stateValue,long zip) { streetAddress = stAddress; city = cityValue; state = stateValue; zipCode = zip; } }
Thanks
hi
do one thing copy this program and again past on new
window and then save it with same name
then it will work
Reply With Quote