吉软-java-第五次作业
2017-11-04 00:00
309 查看
1.班级类
public class Classroom {
int num;
String name;
public Classroom(){}
public Classroom(int num,String name){
this.num=num;
this.name=name;
}
public void displayNum(){
System.out.println("班级的编号为:"+num);
System.out.println("班级名为:"+name);
}
}
2.学生类
public class Student {
int num;
int classNum;
String name;
int age;
char sex;
String address;
int tel;
String Email;
public Student(){}
public Student(int num,int classNum,String name){
this.num=num;
this.classNum=classNum;
this.name=name;
}
public void display(){
System.out.println("编号为:"+num+"的学生在"+classNum+"班");
System.out.println("姓名:"+name+",年龄:"+age+",性别:"+sex+",住址:"+address+",电话:"+tel+",邮箱:"+Email);
}
}
3.水果类
public class Fruits {
String fruitsName;
int fruitsNum;
double fruitsPrice;
public void displayFruits(){
System.out.println("水果:"+fruitsName+",进了"+fruitsNum+"个,"+"每斤"+fruitsPrice+"元");
}
}
4.体积类
public class BoxVolume {
double length;
double width;
double height;
public double volume(){
return length*width*height;
}
public static void main(String[] args){
BoxVolume box1=new BoxVolume();
BoxVolume box2=new BoxVolume();
BoxVolume box3=new BoxVolume();
box1.length=3;
box1.width=4.5;
box1.height=5.6;
System.out.println("盒子1的体积为:"+box1.volume());
box2.length=4;
box2.width=3;
box2.height=5;
System.out.println("盒子2 的体积为:"+box2.volume());
box3.length=1.2;
box3.width=8.9;
box3.height=5;
System.out.println("盒子3的体积为:"+box3.volume());
}
}
public class Classroom {
int num;
String name;
public Classroom(){}
public Classroom(int num,String name){
this.num=num;
this.name=name;
}
public void displayNum(){
System.out.println("班级的编号为:"+num);
System.out.println("班级名为:"+name);
}
}
2.学生类
public class Student {
int num;
int classNum;
String name;
int age;
char sex;
String address;
int tel;
String Email;
public Student(){}
public Student(int num,int classNum,String name){
this.num=num;
this.classNum=classNum;
this.name=name;
}
public void display(){
System.out.println("编号为:"+num+"的学生在"+classNum+"班");
System.out.println("姓名:"+name+",年龄:"+age+",性别:"+sex+",住址:"+address+",电话:"+tel+",邮箱:"+Email);
}
}
3.水果类
public class Fruits {
String fruitsName;
int fruitsNum;
double fruitsPrice;
public void displayFruits(){
System.out.println("水果:"+fruitsName+",进了"+fruitsNum+"个,"+"每斤"+fruitsPrice+"元");
}
}
4.体积类
public class BoxVolume {
double length;
double width;
double height;
public double volume(){
return length*width*height;
}
public static void main(String[] args){
BoxVolume box1=new BoxVolume();
BoxVolume box2=new BoxVolume();
BoxVolume box3=new BoxVolume();
box1.length=3;
box1.width=4.5;
box1.height=5.6;
System.out.println("盒子1的体积为:"+box1.volume());
box2.length=4;
box2.width=3;
box2.height=5;
System.out.println("盒子2 的体积为:"+box2.volume());
box3.length=1.2;
box3.width=8.9;
box3.height=5;
System.out.println("盒子3的体积为:"+box3.volume());
}
}