3. Define a notebook class with
two attributes: color (char) and cpu model (int). [Will do questions]
• 3.1 and two no-argument constructor has the Senate; arg constructor may have
to assign for each property while creating an object;
methods • 3.2 output notebook information
• 3.3 and then write a test class, Test the various
methods of the notebook class .
package lei; public class Notebook { char color; int cpu; public void xx () { System.out.println ( "notebook color is:" + color + "; cpu model is:" + cpu); } }
package lei; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub Notebook n1=new Notebook(); n1.cpu=12; n1.color='b'; n1.xx(); } }
5, define two classes, described as follows: [will do questions]
• 5.1 definition of a human the Person:
• 5.1.1 define a method sayHello (), you can send out to ask each other
greeting "the Hello, My name IS XXX"
• 5.1 .2 has three attributes: name, height, and weight
• 5.2 defines a PersonCreate class:
• 5.2.1 creates two objects, namely zhangsan, 33 years old, 1.73
; lisi, 44, 1.74
• 5.2.2 calls the sayHello of the objects respectively ()method.
package lei; public class Person { String name; double height; int age; public void sayHello(){ System.out.println("hello,my name is "+name); System.out.println("hello,my height is "+height); System.out.println("hello,my age is "+age); } }
package lei; public class PersonCreate { public static void main(String[] args) { // TODO Auto-generated method stub Person p1=new Person(); p1.name="zhangsan"; p1.height=1.73; p1.age=33; p1.sayHello(); Person p2 = new Person(); p2.name="lishi"; p2.height=1.74; p2.age=44; p2.sayHello(); } }