第一题
944E1D34-3738-4cd9-830F-771609A2D601.png
代码
//Circle
public class Circle
{
double r;
public Circle()
{
super();
}
public Circle(double r)
{
this.r = r;
}
public double showArea(){
return 3.14*r*r;
}
public double showPerimeter(){
return 3.14*r*2;
}
}
//测试类
public class TextCircle
{
public static void main(String[] args)
{
Circle circle=new Circle(8);
System.out.println("半径为:"+circle.r+",面积为:"+circle.showArea());
System.out.println("半径为:"+circle.r+",周长为:"+circle.showPerimeter());
}
}
运行截图
{103095BA-8A27-4564-A743-7ED626ADCFB3}_20200721181823.jpg
第二题
F494D8ED-AFDC-4a30-B634-0194904105F1.png
代码
//MyDate
public class MyDate
{
int year;
int month;
int day;
public MyDate(int year, int month, int day)
{
this.year = year;
this.month = month;
this.day = day;
}
public int getYear()
{
return year;
}
public void setYear(int year)
{
this.year = year;
}
public int getMonth()
{
return month;
}
public void setMonth(int month)
{
this.month = month;
}
public int getDay()
{
return day;
}
public void setDay(int day)
{
this.day = day;
}
public void showDate(){
System.out.println("日期:"+year+"年"+month+"月"+day+"日");
}
public void isBi(){
if(year%4==0&&year%100!=0){
System.out.println(year+"年是闰年");
}else if(year%100==0&&year%400==0){
System.out.println(year+"年是闰年");
}else {
System.out.println(year+"年不是闰年");
}
}
}
//测试类
public class TextMyDate
{
public static void main(String[] args)
{
MyDate myDate=new MyDate(1900,1,1);
myDate.showDate();
myDate.isBi();
}
}
运行截图
{02C86DDD-1696-41D2-BAC5-44DD87FB3A18}_20200721193747.jpg
第三题
E1A00717-A916-4bfb-ACCC-63A48F9092B4.png
代码
//Card
public class Card
{
String suit;
String figure;
public Card(String suit, String figure)
{
this.suit = suit;
this.figure = figure;
}
public void showCard(){
System.out.println(suit+figure);
}
}
//测试类
public class TextCard
{
public static void main(String[] args)
{
Card card = new Card("黑桃","A");
card.showCard();
}
}
运行截图
{AF96F1AF-7500-4868-9D7F-77595257339F}_20200721193904.jpg
第四题
代码
//Manager
public class Manager
{
String name;
String num;
int salary;
public Manager()
{
super();
}
public Manager(String name, String num, int salary)
{
this.name = name;
this.num = num;
this.salary = salary;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getNum()
{
return num;
}
public void setNum(String num)
{
this.num = num;
}
public int getSalary()
{
return salary;
}
public void setSalary(int salary)
{
this.salary = salary;
}
public void Intro(){
System.out.println("经理姓名:"+name);
System.out.println("工号:"+num);
}
public void showSalary(){
System.out.println("基本工资为"+salary+",奖金3000");
}
public void work(String string){
System.out.println(string);
}
}
//Coder
public class Coder
{
String name;
String num;
int salary;
public Coder()
{
super();
}
public Coder(String name, String num, int salary)
{
this.name = name;
this.num = num;
this.salary = salary;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getNum()
{
return num;
}
public void setNum(String num)
{
this.num = num;
}
public int getSalary()
{
return salary;
}
public void setSalary(int salary)
{
this.salary = salary;
}
public void Intro(){
System.out.println("程序员姓名:"+name);
System.out.println("工号:"+num);
}
public void showSalary(){
System.out.println("基本工资为:"+salary+",奖金无");
}
public void work(String string){
System.out.println(string);
}
}
//测试类
public class TextCM
{
public static void main(String[] args)
{
Manager manager = new Manager("James","9527",15000);
manager.Intro();
manager.showSalary();
manager.work("正在努力的捉着管理工作,分配任务,检查员工提交上来的代码......");
System.out.println("=====================================");
Coder coder = new Coder("Kobe","0025",10000);
coder.Intro();
coder.showSalary();
coder.work("正在努力写代码......");
}
}
运行截图
{DA015285-CF2A-4F27-AE2A-E44A713755FB}_20200721193952.jpg
第五题
D34F9DD4-DF13-4aae-BD5F-0598140A1A31.png
代码
//Teacher
public class Teacher
{
String name;
int age;
String content;
public Teacher(String name, int age, String content)
{
this.name = name;
this.age = age;
this.content = content;
}
public void eat(){
System.out.println("年龄为"+age+"的"+name+"正在吃饭......");
}
public void teach(){
System.out.println("年龄为"+age+"的"+name+"正在亢奋的讲着"+content+"的知识......");
}
}
//Student
public class Student
{
String name;
int age;
String content;
public Student(String name, int age, String content)
{
this.name = name;
this.age = age;
this.content = content;
}
public void eat(){
System.out.println("年龄为"+age+"的"+name+"正在吃饭......");
}
public void study()
{
System.out.println("年龄为" + age + "的" + name + "专心致志的听着" + content + "的知识......");
}
}
//测试类
public class TextTS
{
public static void main(String[] args)
{
Teacher teacher = new Teacher("周老师",30,"java面向对象");
teacher.eat();
teacher.teach();
Student student = new Student("韩同学",18,"java面向对象");
student.eat();
student.study();
}
}
运行截图
{90749BBD-8D1D-4091-AB0D-C30188A64AC0}_20200721194054.jpg