编程语言
首页 > 编程语言> > java第三次作业

java第三次作业

作者:互联网

package lalalala;

public class Monkey {
    public Monkey(String s)
    {

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

package lalalala;

public class People extends Monkey{
    public People(String s) 
    {
        super(s);
    }
    @Override
    public void speak() 
    {
        System.out.println("小样的,不错嘛!会说话了!");
    }
    public void think() 
    {
        System.out.println("别说话!认真思考!");
    }
}





package lalalala;

public class E {
    public static void main(String[] args) {
        Monkey m1 = new Monkey("m1");
        People p1 = new People("p1");
        People p2 = new People("p2");
        m1.speak();
        p1.speak();
        p2.speak();
        p1.think();
    }
}






package lalalala;

import java.math.BigDecimal;

public class Rectangle {
    private BigDecimal length;
    private BigDecimal width;
    public Rectangle(BigDecimal length, BigDecimal width)
    {
        this.length = length;
        this.width = width;
    }
    public BigDecimal arithmeticArea()
    {
        return this.length.multiply(width);
    }
    public BigDecimal getLength() {
        return length;
    }
    public void setLength(BigDecimal length) {
        this.length = length;
    }
    public BigDecimal getWidth() {
        return width;
    }
    public void setWidth(BigDecimal width) {
        this.width = width;
    }
    
}




package lalalala;
import java.math.BigDecimal;

public class Cuboid extends Rectangle {
    private BigDecimal hight;
    public Cuboid(BigDecimal length, BigDecimal width, BigDecimal hight) 
    {
        super(length , width);
        this.hight = hight;
    }
    @Override
    public BigDecimal arithmeticArea() 
    {
        return this.hight.multiply(getLength()).multiply(getWidth());
    }
    public BigDecimal getHight() {
        return hight;
    }
    public void setHight(BigDecimal hight) {
        this.hight = hight;
    }
}



package lalalala;

import java.math.BigDecimal;

public class Test {

    public static void main(String[] args) {
        Rectangle r1 = new Rectangle(new BigDecimal("5.14"), new BigDecimal("2.12"));
        Cuboid c1 = new Cuboid(new BigDecimal("8.4") , new BigDecimal("3.2") , new BigDecimal("4.1"));
        System.out.println(r1.arithmeticArea());
        System.out.println(c1.arithmeticArea());
    }

}







package lalalala;

import java.math.BigDecimal;

public class Vehicle {
    private int wheels;
    private BigDecimal weight;
    public Vehicle(int wheels , BigDecimal weight) 
    {
        this.wheels = wheels;
        this.weight = weight;
    }
    public int getWheels() {
        return wheels;
    }
    public void setWheels(int wheels) {
        this.wheels = wheels;
    }
    public BigDecimal getWeight() {
        return weight;
    }
    public void setWeight(BigDecimal weight) {
        this.weight = weight;
    }
    @Override
    public String toString() 
    {
        return "wheels"+this.wheels+" weight"+this.weight;
        
    }
}



package  lalalala;

import java.math.BigDecimal;

public class Car extends Vehicle{
    private int loader;
    public Car(int wheels , BigDecimal weight , int loader) 
    {
        super(wheels , weight);
        this.loader = loader;
    }
    public int getLoader() {
        return loader;
    }
    public void setLoader(int loader) {
        this.loader = loader;
    }
    @Override
    public String toString() 
    {
        return "wheels"+this.getWheels()+" weight"+this.getWeight()+" loader"+this.loader;
    }
}





package lalalala;

import java.math.BigDecimal;

public class Truck extends Car{
    private BigDecimal payload;
    public Truck(int wheels , BigDecimal weight , int loader , BigDecimal payload) 
    {
        super(wheels , weight , loader);
        this.payload = payload;
    }
    public BigDecimal getPayload() {
        return payload;
    }
    public void setPayload(BigDecimal payload) {
        this.payload = payload;
    }
    @Override
    public String toString() 
    {
        return "wheels"+this.getWheels()+" weight"+this.getWeight()+" loader"+this.getLoader()+" payload"+this.payload;

    }
}





package lalalala;

import java.math.BigDecimal;

public class Test2 {

    public static void main(String[] args) {
        Vehicle v1 = new Vehicle(20, new BigDecimal("2.8"));
        System.out.println(v1);
        Car c1 = new Car(30, new BigDecimal("3.1"), 7);
        System.out.println(c1);
        Truck t1 = new Truck(40, new BigDecimal("5.1"), 8, new BigDecimal("20"));
        System.out.println(t1);
    }

}

 

标签:java,第三次,weight,作业,loader,new,wheels,public,BigDecimal
来源: https://www.cnblogs.com/xcvb/p/10792427.html