第二次JAVA作业

1.

class Person {
String name;
char sex;
int age;
String ID;
static void pr(Person x){
System.out.println("姓名:"+x.name+" 性别:"+x.sex+" 年龄:"+x.age+" 身份证号码:"+x.ID);
}
}
public class TestPerson {
public static void main(String[] args) {
Person a=new Person();
Person b=new Person();
a.name="张三";
a.sex='男';
a.age=18;
a.ID="430101010101010101";
b.name="李四";
b.sex='女';
b.age=18;
b.ID="123456789009876543";
Person.pr(a);
Person.pr(b);
}
}

2.

class Phone{
String name;
String model;
static void pr(Phone x){
System.out.println("手机品牌:"+x.name+"手机型号 :"+x.model);
}
}
public class TestPhone {
public static void main(String[] args) {
Phone a=new Phone();
Phone b=new Phone();
Phone c=new Phone();
a.name="华为";
a.model="荣耀3C";
b.name="联想";
b.model="A3600D";
c.name="小米";
c.model="note";
Phone.pr(a);
Phone.pr(b);
Phone.pr(c);
}
}

3.

class Book{
String name;
int num;
String zhu;
String chu;
String time;
int page;
float price;
static void pr(Book x){
System.out.println("书名:"+x.name+" 书号:"+x.num+" 作者:"+x.zhu+" "
+ " 出版社:"+x.chu+" 出版时间:"+x.time+" 页数:"+x.page+" 价格:"+x.price);
}
}
public class TestBook {
public static void main(String[] args) {
Book a=new Book ();
Book b=new Book();
a.name="ads";
a.num=001;
a.zhu="asd";
a.chu="dsa";
a.time="2018.1.1";
a.page=88;
a.price=88;
b.name="qwer";
b.num=002;
b.zhu="qaq";
b.chu="wewq";
b.time="2019.1.1";
b.page=99;
b.price=99;
Book.pr(a);
Book.pr(b);
}
}

4.

import java.util.*;
class Circular{
final float PI=3.14f;
double r;
double h;
static double BottomArea(Circular c) {
return c.PI*c.r*c.r;
}
static double Volume(Circular c) {
return BottomArea(c)*c.h;
}
static void pr(Circular c){
System.out.println("圆底半径:"+c.r+" 高:"+c.h+" 底面积:"+BottomArea(c)+" 体积:"+Volume(c));
}
}
public class TestCircular {
public static void main(String[] args) {
Scanner r=new Scanner(System.in);
Circular c1=new Circular();
Circular c2=new Circular();
System.out.println("请输入两个圆柱的底面半径和高:");
c1.r=r.nextDouble();
c2.r=r.nextDouble();
c1.h=r.nextDouble();
c2.h=r.nextDouble();
Circular.pr(c1);
Circular.pr(c2);
}
}

原文地址:https://www.cnblogs.com/liuxun1031/p/10673323.html