blog new write extend system.in tr1 .sh stat
- import java.util.Scanner;
- //write code here
- class Dog {
- String breed,
- color;
- int weight;
- }
- class SpottedDog extends Dog {
- private String spotColor;
- SpottedDog(String a, int b, String c, String d) {
- breed = a;
- weight = b;
- color = c;
- spotColor = d;
- }
- void showBreed() {
- System.out.println(breed);
- }
- void spotInfo() {
- System.out.println(spotColor);
- }
- }
- class UnspottedDog extends Dog {
- UnspottedDog(String a, int b, String c) {
- breed = a;
- weight = b;
- color = c;
- }
- void showBreed() {
- System.out.println(breed);
- }
- }
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System. in );
- String str1 = scan.next();
- int age1 = scan.nextInt();
- String str2 = scan.next();
- String str3 = scan.next();
- String str4 = scan.next();
- int age2 = scan.nextInt();
- String str5 = scan.next();
- SpottedDog redSpot = new SpottedDog(str1, age1, str2, str3);
- UnspottedDog rover = new UnspottedDog(str4, age2, str5);
- redSpot.showBreed();
- redSpot.spotInfo();
- rover.showBreed();
- }
- }
Java 实验题 3_5_林大锐格平台
来源: http://www.bubuko.com/infodetail-2015843.html