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; constructor can have parameters
at the same time create an object for each property assignment; [not] temporarily
• 3.2 notebook information output method
• 3.3 and Write a test class to test the various methods of the notebook class
.
package Rectangle; public class book { char color; int cpu; public void com() { System.out.println ( "Color is" + color); System.out.println ( "cpu model is" + cpu); } }
package Rectangle; public class Text { public static void main(String[] args) { // TODO Auto-generated method stub book p1 = new book(); p1.color='c'; p1.cpu=5; p1.com(); } }
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 Rectangle; public class person { String name; double height; int age; public void Hello() { System.out.println("Hello,my name is "+name); System.out.println("my height is "+ height); System.out.println("my age is "+ age); } }
package Rectangle; public class PersonCreate { public static void main(String[] args) { // TODO Auto-generated method stub person p1 = new person(); p1.name="zhangsan"; p1.age=33; p1.height=1.73; person p2 = new person(); p2.name="lisi"; p2.age=44; p2.height=1.74; p1.Hello(); p2.Hello(); } }