-
public class Circle
{
int r;
Circle()
{
}
Circle(int r)
{
this.r = r;
}
public int getR()
{
return r;
}
public void setR(int r)
{
this.r = r;
}
public void showArea()
{
double s =3.14 *r *r;
System.out.println("半径为:" +r +"面积为:" + s);
}
public void showPerimeter()
{
double c =2 *3.14 *r;
System.out.println("半径为:" +r +"周长为:" + c);
}
}
public class TextCircle
{
public static void main(String[] args)
{
Circle circle =new Circle(8);
circle.showArea();
circle.showPerimeter();
}
}
-
public class MyDate
{
int year;
int month;
int 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;
}
MyDate(int year, int month, int day)
{
this.year = year;
this.month = month;
this.day = day;
}
public void showDate()
{
System.out.println("日期:" +year +"年" +month +"月" +day +"日");
}
public void isBi()
{
if (year %4 ==0 &&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 md=new MyDate(2020,7,21);
md.showDate();
md.isBi();
}
}
-
public class Card
{
Stringflower;
Stringpoint;
Card(String flower, String point)
{
this.flower = flower;
this.point = point;
}
public void showCard()
{
System.out.println(flower+point);
}
}
public class TextCard
{
public static void main(String[] args)
{
Card card=new Card("黑桃","A");
card.showCard();
}
}
-
public class Manager
{
Stringname;
Stringid;
double salary;
double bonus;
Manager()
{
}
Manager(String name, String id, double salary, double bonus)
{
this.name = name;
this.id = id;
this.salary = salary;
this.bonus = bonus;
}
public StringgetName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public StringgetId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public double getSalary()
{
return salary;
}
public void setSalary(double salary)
{
this.salary = salary;
}
public double getBonus()
{
return bonus;
}
public void setBonus(double bonus)
{
this.bonus = bonus;
}
public void intro()
{
System.out.println("经理姓名:" +name +"\n" +"工号:" +id);
}
public void showSalary()
{
System.out.println("基本工资为" +salary +",奖金为" +bonus);
}
public void work()
{
System.out.println("正在努力地做着管理工作,分配任务,检查员工提交上来的代码");
}
}
public class Coder
{
Stringname;
Stringid;
double salary;
Coder()
{
}
Coder(String name, String id, double salary)
{
this.name = name;
this.id = id;
this.salary = salary;
}
public StringgetName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public StringgetId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public double getSalary()
{
return salary;
}
public void setSalary(double salary)
{
this.salary = salary;
}
public void intro()
{
System.out.println("程序员姓名:" +name +"\n" +"工号:" +id);
}
public void showSalary()
{
System.out.println("基本工资为" +salary +",奖金无");
}
public void work()
{
System.out.println("正在努力写代码......");
}
}
public class TextManagerCoder
{
public static void main(String[] args)
{
Manager m =new Manager("James", "9527", 15000, 3000);
m.intro();
m.showSalary();
m.work();
System.out.println("=============");
Coder c =new Coder("Kobe", "0025", 10000);
c.intro();
c.showSalary();
c.work();
}
}
-
public class Teacher
{
Stringname;
int age;
Stringcontent;
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 +"......");
}
}
public class Student
{
Stringname;
int age;
Stringcontent;
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 TextTeacherStudent
{
public static void main(String[] args)
{
Teacher t =new Teacher("周老师", 30, "亢奋地讲着java面向对象的知识......");
t.eat();
t.teach();
Student s =new Student("韩同学", 18, "专心致志地听着java面向对象的知识");
s.eat();
s.study();
}
}