public class Circle {
private double r;
Circle(){
}
Circle(double r){
this.r=r;
}
public double getR() {
return r;
}
public void setR(double r) {
this.r = r;
}
public void showArea(){
System.out.println("圓形面積:"+(2*3.14*r));
}
public void showPermeter(){
System.out.println("圓形周長:"+(3.14*r*r));
}
}
TeseCircle
public class TestCircle {
public static void main(String[] args) {
Circle circle = new Circle(8);
circle.showArea();
circle.showPermeter();
}
}
public class MyDate {
private int year;
private int month;
private int day;
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%400==0 || year%4==0 && year%100!=0){
System.out.println(year+"是閏年");
}else
System.out.println(year +"不是閏年");
}
}
TestDate
public class TestMyDate {
public static void main(String[] args) {
MyDate myDate=new MyDate(1900,1,1);
myDate.showDate();
myDate.isBi();
}
}
public class Card {
String hs;
String sum;
Card(String hs,String sum){
this.hs=hs;
this.sum=sum;
}
public String getHs() {
return hs;
}
public void setHs(String hs) {
this.hs = hs;
}
public String getSum() {
return sum;
}
public void setSum(String sum) {
this.sum = sum;
}
public void showCard(){
System.out.println("牌面信息"+hs+sum);
}
}
TestDate
public class TestCard {
public static void main(String[] args) {
Card card=new Card("黑桃","A");
card.showCard();
}
}
Manageer
public class Manager {
String name;
String num;
String money;
Manager(){
}
Manager( String name,String num,String money){
this.name=name;
this.num=num;
this.money=money;
}
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 String getMoney() {
return money;
}
public void setMoney(String money) {
this.money = money;
}
public void intor(){
System.out.println(name+num);
}
public void showSalary(){
System.out.println(money);
}
public void work(){
System.out.println("工作信息");
}
}
Coder
public class Coder {
String name;
String num;
String money;
Coder(){
}
Coder( String name,String num,String money){
this.name=name;
this.num=num;
this.money=money;
}
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 String getMoney() {
return money;
}
public void setMoney(String money) {
this.money = money;
}
public void intor(){
System.out.println(name+num);
}
public void showSalary(){
System.out.println(money);
}
public void work(){
System.out.println("工作信息");
}
}
TsetCoder
public class TestManager {
public static void main(String[] args) {
Coder coder=new Coder("kobe","0025","基本工資為10000浅碾,獎金無");
Manager manager=new Manager("james","9527","基本工資為15000徙赢,獎金為3000");
manager.intor();
manager.showSalary();
manager.work();
System.out.println("=======================");
coder.intor();
coder.showSalary();
coder.work();
}
}
Teacher
public class Teacher {
String num;
int age;
String content;
Teacher(String num,int age,String content){
this.num=num;
this.age=age;
this.content=content;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public void eat(){
System.out.println("年齡為"+age+"的"+num+"正在吃飯");
}
public void teach(){
System.out.println("年齡為"+age+"的"+num+content);
}
}
Student
public class Student {
String num;
int age;
String content;
Student(String num,int age,String content){
this.num=num;
this.age=age;
this.content=content;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public void eat(){
System.out.println("年齡為"+age+"的"+num+"正在吃飯");
}
public void study(){
System.out.println("年齡為"+age+"的"+num+content);
}
}
TestTeacher
public class TestStudent {
public static void main(String[] args) {
Student student=new Student("韓同學",18,"學習java");
Teacher teacher=new Teacher("周老師",30,"講著java");
teacher.eat();
teacher.teach();
student.study();
student.eat();
}
}