Hi there
i copied below coding from the book.but still cant run the program.i noticed there are two class , they are class student and class obj.i tried separate both class in different class file -> Student.java/Student.class and obj.java/obj.class , but i still cant run the program.Pls help.
Thanks in advance
----------------------------------
public class Student { private String name; private int matricNo; private int yearOfBirth; private int age; private double fees; private int numberOfCoursesRegistered; private String[ ] subjectName; private boolean registered= false; public Student(String NAME, int MATRIC, int B_YEAR) { name= NAME; yearOfBirth=B_YEAR; matricNo= MATRIC; numberOfCoursesRegistered=0; subjectName= new String[3]; calculateAge(); } private void calculateAge(){ int currentYear=2008; age= currentYear-yearOfBirth; }//calculateAge public void calculateFee(){ if (registered==true) fees=numberOfCoursesRegistered*350; }//calculateFee public void registerSubject (String subject1){ if (registered==false) { subjectName[0]=subject1; numberOfCoursesRegistered=1; registered=true; } else System.out.println("You already registered"); }// registerSubject public void registerSubject (String subject1, String subject2){ if (registered==false) { subjectName[0]=subject1; subjectName[1]=subject2; numberOfCoursesRegistered=2; registered=true; } else System.out.println("You already registered"); }// registerSubject public void registerSubject (String subject1, String subject2, String subject3){ if (registered==false) { subjectName[0]=subject1; subjectName[1]=subject2; subjectName[3]=subject3; numberOfCoursesRegistered=3; registered=true; } else System.out.println("You already registered"); } // registerSubject public void displaylnfo ( ) { if (registered==true){ System.out.println("Name: " + name); System.out.println("Matric: " + matricNo); System.out.println("Year of Birth: " + yearOfBirth); System.out.println("age " +age); System.out.println("Fees: " + fees); System.out.println("No of courses registered:+numberOfCoursesRegistered"); System.out.println("Courses registered are:"); for (int count=0; count < numberOfCoursesRegistered; count++) System.out.println(subjectName[count]); } //if else System.out.println("Information cannot be displayed because you have not registered"); } //displayInfo }//class --------------------------------------------------------------------------------------- class obj{ public static void main(String[]args){ Student John = new Student ("John Smith" , 2345 , 1969); John.registerSubject("Java Programming"); John.calculateFee(); } }