Programming is completed the following requirements:
Class Grade categories:
Properties: number, name, address,
defined: constructor with no arguments, there constructor parameter
definition method: displaying information classes.
Student categories:
attributes: Student ID, name, age, where the class
definition method: display student information (student number, name, sex, age, class number, class name ) // g red annotation is a reference type with grade class created (28 lines of code)
Note: where the class should be the class of the class type
test class:
create a class object through the constructor have parameters,
by constructor with no arguments, students create a class object
call information display method for displaying student information
. 1 class Grade { 2 // attributes: ID, name, address . 3 int NUM; . 4 String name; . 5 String address; . 6 . 7 // constructor with no arguments: . 8 public Grade () { . 9 10 } . 11 // has parameters configured method 12 is public Grade ( int NUM, String name, String address) { 13 is the this .num = NUM; 14 the this .name = name; 15 the this .Address = address; 16 } 17 // method: display information about students 18 public void Show () { 19 System.out.println ( "Class number:" + num + "\ n Class Name:" + name + "\ n class address" + address) ; 20 is } 21 is } 22 is class Student { 23 is // properties: school, name, sex, age, where the class 24 int ID; 25 String name; 26 is char sex; 27 int Age; 28 Grade Grade new new G = () ; // Note: when g has no value, the default value is null 29 // method: display student information (student number, name, sex, age, class number, class name) 30 public void the showInfo () { 31 is System.out.println ( "Student information is as follows:" ); 32 System.out.println ( "Student ID:" + id + "\ n Name:" + name + "\ n Gender: "+ sex +" \ n Age: "+ age +" \ n number of classes: "+ g.num +" \ n class name: "+ g.name); 33 is } 34 is } 35 class the Test { 36 public static void main (String [] args) { 37 [ // by reference constructor has created an object class 38 is Grade Grade = new new Grade (123, "class one", "one hundred and one" ); 39 // by no constructor parameters, to create an object class students 40 Student = S new newStudent (); 41 is // call the display method of displaying information student information 42 is s.showInfo (); 43 is } 44 is }