Results 1 to 3 of 3
  1. #1
    H0AX is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default Two Class Program but No Output or Error

    Am writing this program using two classes for my school project from last 4 days. I have completed this program I think but when am running this program, it shows no error also it doesn't show any logic or runtime error..just got blank screen after compiling. Am wondering that why its not printing anything..trying from last 8-9 hrs but no luck. I bet that I missed something silly and cant figure that out. So if any one can help me then I greatly appreciate. Thank You

    Java Code:
    public class Student   
    {
    
    private String name; //Name of Student
    private int matricNo; //Student Number
    private int yearOfBirth; //Students DOB
    private int age; //Students Age
    private double fees; //Fees for the each course
    private int numberOfCoursesRegistered; //number of courses that students wants to register
    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=2010;
    age= currentYear-yearOfBirth;
    
    }//calculateAge
    
    
    public void calculateFee()
    { 
    
    if (registered==true) 
    
    fees=numberOfCoursesRegistered*300; 
    
    }//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
    This is another main class

    Java Code:
    public class FinalStudent
    {
    
    	public static void main(String[]args)
    	{
    
    		Student John = new Student ("John Smith" , 2345 , 1969);
    
    		John.registerSubject("Java Programming");
    		John.calculateFee();
    	}
    
    }

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Well, two things I see:

    Java Code:
    public void displaylnfo ( )
    1. Did you mean to call this method displayInfo() (the comment at the end of the method suggests that you did)?

    2. Did you mean to call that method at some point?

    -Gary-

  3. #3
    H0AX is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default thanks

    O my god ..i cant believe i left that...thanks gcalvin..its working fine right now :D thanks for ur help

Similar Threads

  1. Replies: 2
    Last Post: 09-22-2011, 10:48 PM
  2. Wrong Output (Java Program)
    By poupas in forum New To Java
    Replies: 12
    Last Post: 11-28-2010, 05:28 PM
  3. Replies: 3
    Last Post: 11-11-2010, 09:12 AM
  4. Replies: 1
    Last Post: 07-03-2009, 09:41 PM
  5. Program can run but output all null
    By matt_well in forum New To Java
    Replies: 15
    Last Post: 07-24-2008, 09:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •