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();
}
}
|