java第二次作业

1.编写“人”类及其测试类。
1.1 “人”类:
 类名:Person
 属性:姓名、性别、年龄、身份证号码
 方法:在控制台输出各个信息

1.2 测试类
 类名:TestPerson
 方法:main
 对象:(张三,男,18,430101010101010101)
(李四,女,18,123456789009876543)
package orange;
public class Person {
String name;
char sex;
int age;
String num;
public void R(String name,char sex,int age,String num) {
System.out.println("姓名:"+name+"\n性别:"+sex+"\n年龄:"+age+"\n身份证号码:"+num);
}
public static void main(String[] args) {
Person people = new Person();
people.R("张三",'男',18,"430101010101010101");
people.R("李四",'女',18,"123456789009876543");
}
}
2.编写“手机”类及其测试类。
2.1 “手机”类:
 类名:Phone
 属性:手机品牌、手机型号
 方法:在控制台输出手机信息
2.2 测试类
 类名:TestPhone
 方法:main
 对象:(华为,荣耀3C)
(联想,A3600D)
(小米,note)

package orange;

public class Phone {
String brand;
String type;
public void sj(String brand,String type) {
System.out.print("手机品牌"+brand+"\t手机型号"+type+"\n");
}
public static void main(String[] args) {
Phone Phone = new Phone();
Phone.sj("华为","荣耀3C");
Phone.sj("联想","A3600D");
Phone.sj("小米","note");
}

}
3.编写“书籍”类及其测试类。
3.1 “书籍”类
 类名:Book
 属性:书名、书号、主编、出版社、出版时间、页数、价格
 方法:在控制台输出每本书的信息
3.2 测试类
 创建2个对象,并调用方法

package orange;

public class S {
String title;
int num;
String editor;
String press;
int time;
int pages;
double price;
public void S(String title,int num,String editor,String press,int time,int pages,double price) {
System.out.println("书名:"+title+"\t书号:"+num+"\t主编:"+editor+"\t出版社:"+press+"\t出版时间:"+time+"\t页数:"+pages+"\t价格:"+price+"\n");
}

public static void main(String[] args) {
  S Book   = new S();
    Book.S("白夜行",1,"东野圭吾","日本出版社",1999,55,48.2);
    Book.S("挪威的森林",2,"村上春树","日本出版社",2000,59,40.2);
}

}
4.编写“圆柱体”类及其测试类。
4.1 “圆柱体”类
 属性:圆底半径、高,
 方法1:计算底面积
 方法2:计算体积
 方法3:打印圆底半径、高、底面积和体积。
4.2 测试类
 创建2个对象,并调用方法

package orange;

public class Y {
final static double p=3.14;
int r;
int h;
float s;
float v;
public void Y(int r,int h) {
System.out.print("半径"+r+"\t高"+h+"\t底面积"+s+"\t体积"+v+"\n");
}
public void S1(int r) {
s= (float) (prr);}
public void jisuan2(int r,int h) {
v=(float) (rrp*h);
}
public static void main(String[] args) {
Y circle = new cY();
circle.jisuan1(2);
circle.jisuan2(2,3);
circle.print(2,3);
circle.jisuan1(3);
circle.jisuan2(3,4);
circle.print(3,4);
}

}

posted @ 2019-04-08 20:12  杨垚1  阅读(154)  评论(0编辑  收藏  举报