5 Replies - 12912 Views - Last Post: 30 July 2010 - 04:51 PM Rate Topic: -----

#1 Jbiso  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-July 10

Java Student Class

Posted 29 July 2010 - 11:15 PM

Hello

I need some help with my code, I can't find any logic errors, but it seems to crash when I run it. My project is to create a code to maintain student records for a college. There are two Java classes: Student and EnrolledCourse. It's not quite finish yet, but i can't correct any mistakes because i can't run it. Please, any help would be awesome.

package cis35a.project4.JoshBiso;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Date;

class Student {
     private Scanner in = new Scanner(System.in);
     private String studentName;
     private long studentID;
     private String address;
     private String phone;
     private boolean fulltimeStatus;
     private float gpa;
     private ArrayList courseList;

public Student(){
}
public Student(String studentName, long studentID){
      this.studentName=studentName;
      this.studentID=studentID;
}
public Student(String studentName, long studentID, String address, String phone, boolean fulltimeStatus, float gpa){
      this.studentName = studentName;
      this.studentID= studentID;
      this.address=address;
      this.phone=phone;
      this.fulltimeStatus= fulltimeStatus;
      this.gpa=gpa;
}




public void setStudentName(String studentName){
      this.studentName=studentName;

}
 public void setStudentID(long studentID){
      this.studentID=studentID;
}
 public void setAddress(String address){
      this.address=address;
 }
 public void setPhone(String phone){
      this.phone=phone;}

 public boolean setfulltimeStatus(boolean fulltimeStatus){
 if(courseList.size()>=3){
    this.fulltimeStatus=fulltimeStatus;
    System.out.print("Fulltime Student");
    return true;
 }
 else {
    this.fulltimeStatus=fulltimeStatus;
    System.out.print("Parttime Student");
    return false;}

 }
 public void setGpa(float gpa){
 for(int i=1;i<=courseList.size();i++){
 }


 }
 public void setCourseList(EnrolledCourse className){
     
     this.courseList.add(className);}

public String getStudentName(){
    studentName=in.next();
    return studentName;
  }
public boolean getFulltimeStatus(){
    return fulltimeStatus;
  }
public long getID(){
    return studentID;
  }

public String getAddress(){
    return address;
  }

public String getPhone(){
    return phone;
  }

public boolean getStatus(){

    return true;
  }
public float getGPA(){
    return gpa;
  }

public ArrayList getCourseList(){

    return courseList;
  }

public boolean addCourse(EnrolledCourse courseName){
    for(int i=1; i<courseList.size();i++){
        if(!courseList.contains(courseName)){
            courseList.add(i);
            return true;

        }
    }
    return false;
   }

   

public boolean dropCourse(int callNumber){

        if(courseList.contains(callNumber)){
        courseList.remove(callNumber);
        return true;
        }
    return false;
       }

public boolean updateGrade(int callNumber, char newGrade){
    if(courseList.contains(callNumber)){
    

    return true;}
return false;}
//public char getCourseGrade(String courseName){

//}
public String hasEnrolled(String courseName){
return courseName;
}

}



 class EnrolledCourse{
     private String courseName;
     public int callNumber;
     private String instructor;
     private char grade;
     private String quarterTaken;
     private Date gradeRecordedON;

     EnrolledCourse(){}
     EnrolledCourse(String courseName, int callNumber, String instructor, String quarterTaken){
        this.courseName=courseName;
        this.callNumber=callNumber;
        this.instructor=instructor;
        this.quarterTaken=quarterTaken;
     }
    EnrolledCourse(String courseName, int callNumber, String instructor, char grade,  String quarterTaken, Date gradeRecordedOn){
        this.courseName=courseName;
        this.callNumber=callNumber;
        this.instructor=instructor;
        this.grade=grade;
        this.quarterTaken=quarterTaken;
    }


public String toString(){
return String.format( "%s: %s %s\n%s: %s %s\n%s: %s %s\n%s: ",
        "Course Name", courseName,
         "Course Number", callNumber,
         "Instructor", instructor

        );
}
public void setCourseName(String courseName){
    this.courseName=courseName;
   }
public void setCallNumber(int callNumber){
    this.callNumber=callNumber;
   }
public void setInstructor(int callNumber,String instructor){
    this.instructor=instructor;
   }
public void setGrade(int callNumber ,char grade){
    this.grade=grade;
   }
public void setQuarterTaken(int callNumber, String quarterTaken){
    this.quarterTaken=quarterTaken;
   }
public void setGradeRecordedON(Date gradeRecordedOn){
    this.gradeRecordedON=gradeRecordedOn;
   }

public String getCoursename(){
    return courseName;
   }

public int getCallNumber(){
    return callNumber;
   }
public String getInstructor(){
    return instructor;
}
public char getGrade(){
return grade;
    }
public String getQuarterTaken(){
    return quarterTaken;
     }
public Date getGradeRecordedOn(){
    return gradeRecordedON;
      }
 }



class classJoshBiso{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
         EnrolledCourse math = new EnrolledCourse("Math63: Differential Equations", 2150, "Alfred Einstein","fall 2010");
         EnrolledCourse physics = new EnrolledCourse("Physics17B: Quantum Physics", 2250, "Phil Jackson", "Winter 2010");
         EnrolledCourse history = new EnrolledCourse("HIS4N: Norse Mythology", 2100, "Odin", "Winter 2010");
         EnrolledCourse compscience = new EnrolledCourse("CS1337: StarcraftII", 1337, "Jim Raynor", "summer 2010");

           //student1
           Student student1 = new Student("Uzumaki Naruto", 31192556);
           student1.setAddress("9123 Konoha Ct, Fire Country");
           student1.setPhone("408-238-5836");

           System.out.println("Student Name" + student1.getStudentName() + "ID" + student1.getID() +
           "Address" + student1.getAddress() + "phone" + student1.getPhone() + "full-time" + student1.getFulltimeStatus());
           student1.addCourse(math);



           //student2
           Student student2 = new Student ("Manny Pacquiao", 12345678);
           student2.setAddress("7timeChampion St, General Santos City");
           student2.setPhone ("408-386-8239");



           System.out.println("Student Name" + student1.getStudentName() + "ID" + student1.getID() +
           "Address" + student1.getAddress() + "phone" + student1.getPhone() + "full-time" + student1.getFulltimeStatus());
            student2.addCourse(history);


           //student3
           Student student3 = new Student ("Thrall Durotan", 23468976);
           student3.setAddress("Valley of Honor, Orgrimmar City");
           student3.setPhone("Mok-nath-tar");

           System.out.println("Student Name" + student1.getStudentName() + "ID" + student1.getID() +
           "Address" + student1.getAddress() + "phone" + student1.getPhone() + "full-time" + student1.getFulltimeStatus());
           student3.addCourse (compscience);


    }

}



Edited by macosxnerd101: Welcome to DIC! :) Please, :code:.

Is This A Good Question/Topic? 0
  • +

Replies To: Java Student Class

#2 aniri  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 54
  • View blog
  • Posts: 657
  • Joined: 24-November 09

Re: Java Student Class

Posted 29 July 2010 - 11:41 PM

Please use code tags when posting code. ([code ] [/code ])

What errors are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 guido-granobles  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 171
  • View blog
  • Posts: 617
  • Joined: 02-December 09

Re: Java Student Class

Posted 30 July 2010 - 06:56 AM

public String getStudentName() {
	studentName = in.next();
	return studentName;
}



why do you have in.next() right there? what does it make?.. it doesn't make sense for me and it's hanging the application.

This post has been edited by guidojavier: 30 July 2010 - 06:56 AM

Was This Post Helpful? 0
  • +
  • -

#4 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 293
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Java Student Class

Posted 30 July 2010 - 07:04 AM

what^ he means is that you shouldn't be setting grades in a getter method. Scanning should occur in a setter or main method. Also, it seems to me that there are many many empty loops and incomplete code. Please post any error messages you are recieving so we may better aid you
Was This Post Helpful? 0
  • +
  • -

#5 Jbiso  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-July 10

Re: Java Student Class

Posted 30 July 2010 - 04:35 PM

java.lang.NoClassDefFoundError: classJoshBiso
Caused by: java.lang.ClassNotFoundException: classJoshBiso
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: classJoshBiso. Program will exit.
Exception in thread "main" Java Result: 1

View Postguidojavier, on 30 July 2010 - 05:56 AM, said:

public String getStudentName() {
	studentName = in.next();
	return studentName;
}



why do you have in.next() right there? what does it make?.. it doesn't make sense for me and it's hanging the application.


oh, i'm not done with the code yet, but i was tryin to test if it runs well at least.

After taking out the( studentName=in.next();)
am getting this error when i run it.

[error]
Exception in thread "main" java.lang.NullPointerException
Student NameUzumaki NarutoID31192556Address9123 Konoha Ct, Fire Countryphone408-238-5836full-timefalse
at cis35a.project4.Student.addCourse(classJoshBiso.java:110)
at cis35a.project4.classJoshBiso.main(classJoshBiso.java:250)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Was This Post Helpful? 0
  • +
  • -

#6 Jbiso  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-July 10

Re: Java Student Class

Posted 30 July 2010 - 04:51 PM

I am also trying to add and drop courses for each students and call other methods to test the code. Such as my method for adding and dropping classes.

 for addcourse

public boolean addCourse(EnrolledCourse courseName){
    for(int i=1; i<courseList.size();i++){
        if(!courseList.contains(courseName)){
            courseList.add(i);
            return true;

        }
    }
    return false;
   }



and

 dropcourse
public boolean dropCourse(int callNumber){

        if(courseList.contains(callNumber)){
        courseList.remove(callNumber);
        return true;
        }
    return false;
       }




Overall "IF" i finish it the output should come out like this:

Student Name: student_1 Address: Phone: ID: 883386 Fulltime Status: false GPA: 0.0
Add CourseName: CIS_105
Instructor: Instructor_13
Quarter Taken: Fall 2008
Call Number: -1649368010
Grade: C
Grade Recorded On: Thu Jul 29 23:12:32 PDT 2010
Add CourseName: ENG_66
Instructor: Instructor_58
Quarter Taken: Spring 2008
Call Number: -527614378
Grade: F
Grade Recorded On: Thu Jul 29 23:12:32 PDT 2010
Add CourseName: BUS_35
Instructor: Instructor_86
Quarter Taken: Winter 2007
Call Number: -68711927
Grade: W
Grade Recorded On: Thu Jul 29 23:12:32 PDT 2010

This post has been edited by Jbiso: 30 July 2010 - 07:17 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1