java第六次

第一题

package Demo;//沙梦
import java.util.concurrent.Callable;

public class Base {
    public Base(){
        System.out.println("Base");
    }
}
class Child extends Base{
    public Child(){
        System.out.println("Child");
    }
}

ackage Demo;

public class Sample {
    public static void main(String[] args) {
        Child c = new Child();
    }
}

Base
Child

进程已结束,退出代码为 0

第二题

package Demo
//沙梦
public class Animal {
    private String color;
    private String type;
    private int age;
    private int weight;
    public String getColor(){
        return color;
    }
    public void setColor(String color){
        this.color=color;
    }
    public String getType(){
        return type;
    }
    public void setType(String type){
        this.type=type;
    }
    public int getAge(){
        return age;
    }
    public void setAge(int age){
        this.age=age;
    }
    public int getWeight(){
        return weight;
    }
    public void setWeight(int weight){
        this.weight=weight;
    }
    public abstract void info();
}


package Democracy;
//沙梦
public class Bird extends Animal{
    @Override
    public String getColor(){
        return super.getColor();
    }
    @Override
    public void setColor(String color){
        super.setColor(color);
    }
    @Override
    public String getType(){
        return super.getType();
    }
    @Override
    public void setType(String type){
        super.setType(type);
    }
    @Override
    public int getAge(){
        return super.getAge();
    }
    @Override
    public void setAge(int age){
        super.setAge(age);
    }
    @Override
    public int getWeight(){
        return super.getWeight();
    }
    @Override
    public void setWeight(int weight) {
        super.setWeight(weight);
    }
    @Override
    public void info(){
        System.out.println("我是一只"+getColor()+"的"+getType());
        System.out.println("今年"+getAge()+"岁了");
    }
}


package Demo;

public class Fish extends Animal{
    @Override
    public String getColor(){
        return super.getColor();
    }
    @Override
    public void setColor(String color){
        super.setColor(color);
    }
    @Override
    public String getType(){
        return super.getType();
    }
    @Override
    public void setType(String type){
        super.setType(type);
    }
    @Override
    public int getAge(){
        return super.getAge();
    }
    @Override
    public void setAge(int age){
        super.setAge(age);
    }
    @Override
    public int getWeight(){
        return super.getWeight();
    }
    @Override
    public void setWeight(int weight) {
        super.setWeight(weight);
    }
        @Override
        public void info(){
            System.out.println("我是一条"+getWeight()+"斤重的"+getType());
            System.out.println("今年"+getAge()+"岁了");
        }
    }



package unit7.test2;

public class Test {
    public static void main(String[] args) {
        Animal animal=new Bird();
        animal.setColor("红色");
        animal.setType("鸟");
        animal.setAge(4);
        animal.info();
        Animal animal1=new Fish();
        animal1.setWeight(5);
        animal1.setType("鱼");
        animal1.setAge(2);
        animal1.info();
    }
}



我是一只红色的鸟
今年4岁了
我是一条5斤重的鱼
今年2岁了

进程已结束,退出代码为 0

第三题

package Demo;
//沙梦
public class Two extends Phones {
    public void call(){
    System.out.println("苹果手机打电话");
}
}
class APhone extends Phones {
    public void call(){
        System.out.println("安卓手机打电话");
    }
}
class WPhone extends Phones{
    public void call(){
        System.out.println("Windows Phone 手机打电话");
    }
}

package Demo
public class BaseStation {
    public Phones callPhone(String type){
        if (type.equals("iphone")){
            return new IPhone();
        }else if (type.equals("aphone")){
            return new APhone();
        }else{
            return new WPhone();
        }
    }
}
package Demo``;
import java.util.Scanner;
public class User {
    static Scanner a=new Scanner(System.in);

    public static void main(String[] args) {
        boolean flag=false;
        String b;
        BaseStation c=new BaseStation();
        String d;
        do {
            System.out.println("请问要使用什么手机打电话?1.IPhone      2.APhone       3或其他任意键.WPhone");
            b=a.next();
            if ("1".equals(b)){
                d="iphone";
            }else if ("2".equals(b)){
                d="aphone";
            }else {
                d="wphone";
            }
            Phones phones=c.callPhone(d);
            phones.call();
            System.out.println("还要打电话吗?按n退出,按其他任意字符继续打电话......");
            b=a.next();
            if ("n".equals(b)){
                flag=true;
            }
        }while (!flag);
        System.out.println("嗯,再见!");
    }
}
请问要使用什么手机打电话?1.IPhone      2.APhone       3或其他任意键.WPhone
1
苹果手机打电话
还要打电话吗?按n退出,按其他任意字符继续打电话......
1
请问要使用什么手机打电话?1.IPhone      2.APhone       3或其他任意键.WPhone
2
安卓手机打电话
还要打电话吗?按n退出,按其他任意字符继续打电话......
2
请问要使用什么手机打电话?1.IPhone      2.APhone       3或其他任意键.WPhone
3
Windows Phone 手机打电话
还要打电话吗?按n退出,按其他任意字符继续打电话......
3
请问要使用什么手机打电话?1.IPhone      2.APhone       3或其他任意键.WPhone
g
Windows Phone 手机打电话
还要打电话吗?按n退出,按其他任意字符继续打电话......
n
嗯,再见!

进程已结束,退出代码为 0




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值