Java作业

class Student{
private String name;
private int age;
private String college;
private String depart;
public Student() {}
public Student (String name,int age,String college,String depart) {
this.setName(name);
this.setAge(age);
this.setCollege(college);
this.setDepart(depart);
}
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setCollege(String college) {
this.college = college;
}
public void setDepart (String depart) {
this.depart = depart;
}
public String getName() {
return this.name;
}
public int getAge() {
return this.age;
}
public String getCollege() {
return this.college;
}
public String getDepart() {
return this.depart;
}
public String getInfo() {
return “学生信息如下:” +"\n"+
“姓名” + this.getName() + “\n”+
“年龄” + this.getAge() + “\n”+
“学校” + this.getCollege() + “\n” +
“学院” + this.getDepart();
}
}
/*class Teacher{

}*/
public class A1 {
public static void main (String args[]) {
Student stu1 = new Student(“张三”,22,“shu”,“computer science and techololege”);
System.out.println(stu1.getInfo());
}
}

public class A2 {
public static void main(String [] args) {
Circle circle;
circle = new Circle();
circle.r = 100;
double s = circle.getArea();
System.out.printf("%5.3f,%5.3f",circle.r,s);
}
}
class Circle{
double r;
double getArea() {
double s = 3.14rr;
return s;
}
}

public class A3 {
public static void main(String [] args) {
Rectangle rectangle;
rectangle = new Rectangle();
rectangle.longth = 3;
rectangle.width = 4;
System.out.printf(“一个长为%f,宽为%f的长方形的面积为%f”,rectangle.longth,rectangle.width,rectangle.getArea());
}
}
class Rectangle {
double longth; //声明长方形的变量长
double width; //声明长方形的变量宽
//定义计算面积的方法
double getArea() {
return width*longth;
}
}

public class A4 {
public static void main(String [] args) {
梯形 梯 ;
梯 = new 梯形();

	System.out.printf("%f",梯.getArea());
}

}
class 梯形{
float 上底,下底,高;
梯形(){
上底 = 60; //构造方法
下底 = 100;
高 = 20;
}
梯形(float x,int y,float h){//构造方法
上底 = x;
下底 = y;
高 = h;
}
double getArea() {
double s = (上底+下底)*高/2;
return s;
}
}

你可能感兴趣的:(Java)