2 Replies - 1030 Views - Last Post: 09 December 2010 - 02:03 AM Rate Topic: -----

#1 Guest_Devin*


Reputation:

Student.java

Posted 09 December 2010 - 12:14 AM

The question is to write a main program (Student.java) that tests all methods in your Student class and
also tests the error checking capabilities of the addGrade method. Is this a good start? Also what do I need to do next?
public class Student 
{
   	private String lastName; 
      private String firstName; 
      private int studentID; 
      private int units;   
      private int gradePoints ; 
		
	    // construct a new student with given fields
    public Student(String first, String last, String email, int section) {
        this.first = first;
        this.last = last;
        this.student = student;
        this.units = units;
		  this.grade = grade
    }
    public static void main(String[]args)
    {
         Student s1 = new Student(/*your values here*/);
    }

        /*getters */ 
       public String getLastName()  { } 
       public String getFirstName()  { } 
       public int getStudentID()  { } 
       public int getUnits() { } 
       public int getGradePoints() { } 
 
}


This post has been edited by macosxnerd101: 09 December 2010 - 05:58 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0

Replies To: Student.java

#2 jball34337   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 21
  • Joined: 09-October 10

Re: Student.java

Posted 09 December 2010 - 01:11 AM

Call a method like

getGradePoints();

No need for {}

:beta1:

This post has been edited by jball34337: 09 December 2010 - 01:26 AM

Was This Post Helpful? 0
  • +
  • -

#3 n8schatten   User is offline

  • D.I.C Regular
  • member icon

Reputation: 147
  • View blog
  • Posts: 263
  • Joined: 07-December 10

Re: Student.java

Posted 09 December 2010 - 02:03 AM

  • :code:
  • Your constructor does only assign a value to units since the other variables you assign to don't exist right now.
    E.g.:
    ...
    private String firstName;
    ...
    
    // construct a new student with given fields
    public Student(String first, String last, String email, int section) {
      this.first = first;
    ...
    }
    

    Either rename the variable (line 2) to first or change the assignment in line 7 to this.firstName = first;. Same for the other variables (despite of units of course).
  • Implement those getters.


If you finished these points, you can start by adding code like:
if ("first".equals(s1.getFirstName())) {
  ... //good case
} else {
  ... //bad case
}

to your main-method.
That's how I understand the task description. Please correct me if I got something wrong.
Good luck and show us the results please :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1