Is the following a mis-type.
- Create a Student class as following:
- The Student class has StudentRecord class as an instance variable.
Name it as studentRecord.
- You can use the StudentRecord class from the
MyStudentRecordExampleProject above or you can create a new
one - the only
requirement is that it has to have at least one instance
variable of its
own.
- The Student class has studentId instance variable whose type is
Integer type.
- Move the studentCount static variable from the StudentRecord class
to Student class.
- Rewrite main.java as following
- Create 3 instances of Student class and initialize them accordingly
- use whatever initialization values that are appropriate.
- Display the information of each student including the student id,
name.
- Display the studentCount.
If not why would we introduce another class into this project.
If so I'm a bit confused?
Below is a copy with the instructions given. And I would like a some help on
how to handle the student count.
========================================================================
/*
* The Student class has StudentRecord class as an instance variable.
Name it as studentRecord.
*
* The Student class has studentId instance variable
whose type is Integer type.
* Move the studentCount static variable from
* the StudentRecord class to Student class.
*/
/**
*
* @author trey
*/
public class Student {
// instance variable of Student ID
String studentID;
// Declare static variables.
//studentCount static variable moved from StudentRecord class Now if we
move this variable shouldn't the methods as well. Unless we set the main
method here.
static int studentCount = 0;
// Instance Variable of StudentRecord
StudentRecord studentRecord = new StudentRecord();
public Student()
{
}
public Student(String sID, String name , double sGrade )
{
//
studentID = sID;
//increase student count Error cannot access static methods for
non-static context(method)
studentRecord.increaseStudentCount();
studentCount = studentRecord.getStudentCount();
//set name
studentRecord.setName(name);
//set English Grade
studentRecord.setEnglishGrade(sGrade);
}
}
=======================================================================================
/*
* Rewrite main.java as following
Create 3 instances of Student class and initialize them accordingly
- use whatever initialization values that are appropriate.
Display the information of each student including the student id, name.
Display the studentCount.
/**
*
* @author trey
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// first instance of student
// send studentID, name, grade
Student student1 = new Student("TH1234", "Chris", 89);
// second instance of student
Student student2 = new Student("CWH2345", "Trey", 95);
// third instance of student
Student student3 = new Student("CFH3456", "Chloe", 100);
// Display has not been set up yet
}
}
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en