第三次作业

1

package com.hanqi.test;

public class Instrument {
public void play()
{
System.out.println("弹奏乐器");
}


}


package com.hanqi.test;

public class Wind extends Instrument {

public void play()
{
System.out.println("弹奏wind");
}
public void play2()
{
System.out.println("调用wind的play2");
}

}


package com.hanqi.test;

public class Brass extends Instrument {
public void play()
{
System.out.println("弹奏Brass");
}
public void play2()
{
System.out.println("调用Brass的play2");
}

}


package com.hanqi.test;

public class Music {

public static void main(String[] args) {
Instrument i=new Instrument();
i.play();
Wind w=new Wind();
w.play();
w.play2();
Brass b=new Brass();
b.play();
b.play2();

}

}

 

2

package zhongqiuzuoye;

public class Monkey {

Monkey(String s) 
{}

public void speak()
{
System.out.println("咿咿呀呀......");
}
}


package zhongqiuzuoye;

public class People1 extends Monkey{

People1(String s) {
super(s);
}

public void speak()
{
System.out.println("小样的,不错嘛!会说话了!");
}
public void think()
{
System.out.println("别说话!认真思考!");
}

}


package zhongqiuzuoye;

public class E1 {

public static void main(String[] args) {

Monkey m = new Monkey("tom");
m.speak();

People1 p = new People1("Xiaoming");
p.speak();
p.think();

}

}

 

 3

package jvxing;

public class Jvxing
{
//成员变量
private double width;
private double chang;
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getChang() {
return chang;
}
public void setChang(double height) {
this.chang = height;
}


//成员方法
public double mianji()
{
return this.width*this.chang;
}
}


package jvxing;

public class Cft extends Jvxing
{
//定义新的成员变量高
private double height;

public double getHeight() {
return height;
}

public void setHeight(double height) {
this.height = height;
}

//定义新的成员方法求体积

public double tiji()
{
return this.getChang()*this.getHeight()*this.getWidth();
}
}


package jvxing;

public class Text_jvxing {

public static void main(String[] args) {

//实例化矩形对象求面积
Jvxing j= new Jvxing();
j.setWidth(10);
j.setChang(15.3);
System.out.println("矩形的长为:"+j.getChang()+" 宽为:"+j.getWidth());
System.out.println("矩形的面积为:"+j.mianji());

//实例化长方体对象求体积
Cft c = new Cft();
c.setChang(2);
c.setHeight(3.2);
c.setWidth(100);
System.out.println("长方体的长为:"+c.getChang()+" 宽为:"+c.getWidth()+" 高为:"+c.getHeight());
System.out.println("长方体的体积为:"+c.tiji());

}

}

 

 

4

 

 

package hanqi;

public class Vehicle {

private int wheels;
private int weight;
public int getWheels() {
return wheels;
}
public void setWheels(int wheels) {
this.wheels = wheels;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}

public Vehicle(int wheels,int weight)
{
this.weight=weight;
this.wheels=wheels;
}

}


package hanqi;

public class Car extends Vehicle{

private int loader;

public int getLoader() {
return loader;
}

public void setLoader(int loader) {
this.loader = loader;
}

public Car(int wheels, int weight,int loader)
{
super(wheels,weight);
this.loader=loader;
}

}


package hanqi;

public class Truck extends Car{
private int payload;

public int getPayload() {
return payload;
}

public void setPayload(int payload) {
this.payload = payload;
}

public Truck(int wheels, int weight, int loader, int payload)
{
super(wheels,weight,loader);
this.payload=payload;
}

}


package hanqi;

public class TestVehicle {

public static void main(String[] args) {

Vehicle a = new Vehicle(4,3);
System.out.println("a有:"+a.getWheels()+"个轮子\t:"+a.getWeight()+"吨重");


Car b= new Car(4,3,4);
System.out.println("b有:"+b.getWheels()+"个轮子\t:"+b.getWeight()+"吨重\t可以坐"+b.getLoader()+"个人");

Truck c= new Truck(6,10,5,10);
System.out.println("c有:"+c.getWheels()+"个轮子\t:"+c.getWeight()+"吨重\t可以坐"+c.getLoader()+"个人\t载重"+c.getPayload()+"吨");

}
}

 

posted @ 2019-05-12 10:14  还未如愿见着不朽  阅读(183)  评论(0编辑  收藏  举报