NEFU java课程实验三(锐格)开了个头

7173、



import java.util.Scanner;

class Dog{
    String breed;
    int weight;
    String color;
    public void show(){

    }
}
class UnspottedDogg extends Dog {
    UnspottedDogg(String breed,int wegiht,String color){
        this.breed=breed;
        this.weight=wegiht;
        this.color=color;
    }
    public  void show(){
        System.out.println("这是一只"+breed+"犬");
    }
}
class  SpottedDog extends Dog{
    String spotColor;
    SpottedDog(String breed,int wegiht,String color,String spotColor){
        this.breed=breed;
        this.weight=wegiht;
        this.color=color;
        this.spotColor=spotColor;
    }
    public void show(){
        System.out.println("这是一只"+breed+"体重为"+weight+",颜色为"+color
        );
        System.out.println("这是一只"+breed+",颜色为"+color+",斑点颜色为"+spotColor);
    }
}
public class Main{
    public static void main(String[] args) {
        String breed1,breed2;
      int  weight1,weight2;
        String color1,color2;
        String spotcolor;
        Scanner in =new Scanner(System.in);
        breed1=in.next();
   weight1=in.nextInt();
        color1=in.next();
        spotcolor=in.next();
        breed2=in.next();
        weight2=in.nextInt();
        color2=in.next();
        SpottedDog d1=new SpottedDog(breed1,weight1,color1,spotcolor);
        d1.show();
        UnspottedDogg d2=new UnspottedDogg(breed2,weight2,color2);
        d2.show();
    }
}

7174、



import java.util.Scanner;

class Vehicle{
    int num;
    double weight;
    public Vehicle(int num,double weight){
        this.num=num;
        this.weight=weight;
    }
    public void show(){
        System.out.println("汽车:");
        System.out.println("轮子数:"+num+"个");
        System.out.println("自身重量:"+weight+"吨");
    }
    public Vehicle(){

    }

}
class Car extends Vehicle{
    int Passengers;
    public Car(int num,double weight,int Passengers){
        super(num,weight);
        this.Passengers=Passengers;
    }
    public void show(){
        System.out.println("小轿车:");
        System.out.println("轮子数:"+num+"个");
        System.out.println("自身重量:"+weight+"吨");
        System.out.println("额定乘客数:"+Passengers+"人");
    }
    public Car(){

    }
}
class Truck extends Car{
    double Cargo;
    public Truck(int num,double weight,int Passsengers,double Cargo){
        super(num,weight,Passsengers);
        this.Cargo=Cargo;
    }
    public void show(){
        System.out.println("卡车:");
        System.out.println("轮子数:"+num+"个");
        System.out.println("自身重量:"+weight+"吨");
        System.out.println("额定乘客数"+Passengers+"人");
        System.out.println("载重量"+Cargo+"吨");
    }

}

public class Main {
    public static void main(String[] args) {
//        16 5.4 4 1.5 5 6 4 4 10
        int num1,num2,passenger2,num3,passenger3;
        double weight1,weight2,weight3,cargo3;
        Scanner in =new Scanner(System.in);
        num1=in.nextInt();
        weight1=in.nextDouble();
        num2=in.nextInt();
        weight2=in.nextDouble();
        passenger2=in.nextInt();
        num3=in.nextInt();
        weight3=in.nextInt();
        passenger3=in.nextInt();
        cargo3=in.nextDouble();
        Vehicle v1=new Vehicle(num1,weight1);
        v1.show();
        Car v2=new Car(num2,weight2,passenger2);
        v2.show();
        Truck v3=new Truck(num3,weight3,passenger3,cargo3);
        v3.show();
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小李小于

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值