第一题
public class Circle {
private int r;
Circle(){
};
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 l=3.14*2*r;
System.out.println("半径为:"+r+"周长为:"+l);
}
}
//TestCircle
public class TestCircle {
public static void main(String[] args) {
Circle circle=new Circle();
circle.setR(5);
System.out.println(circle.getR());
circle.showArea();
circle.showPerimeter();
}
}
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 showData() {
System.out.println("日期:" + year + "年" + month + "月" + day + "日");
}
public boolean isBi(boolean flag) {
if (year % 100 != 0 && year % 4 == 0) {
flag = true;
System.out.println(year + "是闰年");
}
if (year % 100 == 0 && year % 400 == 0) {
flag = true;
System.out.println(year + "是闰年");
return flag;}
System.out.println(year+"不是闰年");
return flag;
}
}
测试类
public class TestData {
public static void main(String[] args) {
MyDate mydate=new MyDate(1993,3,4);
mydate.showData();
mydate.isBi(true);
}
}
public class Card {
private String Color;
private String point;
Card(){}
Card(String Color ,String point){
this.Color=Color;
this.point=point;
}
public void showCard(){
System.out.println(Color+point);
}
}
public class TestCard {
public static void main(String[] args) {
Card card=new Card("黑桃","A");
card.showCard();
}
}