栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JAVA实验四

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAVA实验四

public class Application {
    public static void main(String args[]){
        User user=new User();
        for(int i=0;i<5;i++){
            user.setAccount(i);
            user.select();
            user.playGame();
            System.out.println();
        }
    }
}
public class User {
    Character role;
    int account;
    void setRole(Character role) {
        this.role = role;
    }
    void select(){
        int account1=account%6;
        switch (account1){
            case 0:Swordsman swordsman=new Swordsman("帅气的服装","帅气的头发","帅气的外表","Swordsman");
                   setRole(swordsman);
                   break;
            case 1:Thief thief=new Thief("黑色的服装","黑色的头发","伪装的外表","Thief");
                setRole(thief);
                    break;
            case 2:Constable constable=new Constable("官府的服装","官方的发型","官方权威的外表","Constable");
                setRole(constable);
                    break;
            case 3:Civilian civilian=new Civilian("普通的服装","普通的头发","普通的外表","Civilian");
                setRole(civilian);
                   break;
            default:OfficerZhiFu zhiFu=new OfficerZhiFu("官方的服装","官方的头发","官方的外表","ZhiFu");
                  setRole(zhiFu);
                  break;
        }
    }
    void setAccount(int account1){
        account=account1;
    }
    void playGame(){
        role.playGame();
    }
}
abstract public class Character {
    String clothes;
    String hairColor;
    String appearance;
    String name;
    abstract void walk();
    abstract void run();
    abstract void show();
    abstract void speak();
    abstract  void playGame();
    public Character(String clothes,String hairColor,String appearance,String name){
        this.clothes=clothes;
        this.hairColor=hairColor;
        this.appearance=appearance;
        this.name=name;
    }
}
class Civilian extends Character{
        public Civilian(String clothes,String hairColor,String appearance,String name){
            super(clothes,hairColor,appearance,name);
        }
        void walk() {
                System.out.println("普通地走");
        }
        void run() {
                System.out.println("普通地跑:时速10Km/h");
        }
        void show() {
                System.out.println("普通地展示:"+this.clothes+" "+this.hairColor+" "+this.appearance+" "+this.name);
        }
        void speak() {
                System.out.println("普通地说话:我赢了");
        }
        void playGame(){
                walk();
                run();
                show();
                speak();
        }
    }
class Constable extends Character{
    public Constable(String clothes,String hairColor,String appearance,String name){
        super(clothes,hairColor,appearance,name);
    }
    void walk() {
        System.out.println("威风地走");
    }
    void run() {
        System.out.println("威风地跑:时速30Km/h");
    }
    void show() {
        System.out.println("威风地展示:"+this.clothes+" "+this.hairColor+" "+this.appearance+" "+this.name);
    }
    void speak() {
        System.out.println("威风地说话:我赢了");
    }
    void playGame(){
        walk();
        run();
        show();
        speak();
    }
}
class Swordsman extends Character{
    public Swordsman(String clothes,String hairColor,String appearance,String name){
        super(clothes,hairColor,appearance,name);
    }
    void walk() {
        System.out.println("帅气地走");
    }
    void run() {
        System.out.println("帅气地跑:时速50Km/h");
    }
    void show() {
        System.out.println("帅气地展示:"+this.clothes+" "+this.hairColor+" "+this.appearance+" "+this.name);
    }
    void speak() {
        System.out.println("依本大侠看,帅气地说话……:我赢了");
    }
    void playGame(){
        walk();
        run();
        show();
        speak();
    }
}
class Thief extends Character{
    public Thief(String clothes,String hairColor,String appearance,String name){
        super(clothes,hairColor,appearance,name);
    }
    void walk() {
        System.out.println("偷偷摸摸地走");
    }
    void run() {
        System.out.println("偷偷摸摸地跑:时速40Km/h");
    }
    void show() {
        System.out.println("偷偷摸摸地展示:"+this.clothes+" "+this.hairColor+" "+this.appearance+" "+this.name);
    }
    void speak() {
        System.out.println("偷偷摸摸地说话:我赢了");
    }
    void playGame(){
        walk();
        run();
        show();
        speak();
    }
}

class OfficerZhiFu extends Character {
    public OfficerZhiFu(String clothes,String hairColor,String appearance,String name){
        super(clothes,hairColor,appearance,name);
    }
    void walk() {
        System.out.println("官方地走");
    }
    void run() {
        System.out.println("官方地跑:时速25Km/h");
    }
    void show() {
        System.out.println("官方地展示:"+this.clothes+" "+this.hairColor+" "+this.appearance+" "+this.name);
    }
    void speak() {
        System.out.println("依本知府看,官方发言:……");
    }
    void sentence(){
        System.out.println("升堂审案");
    }
    void playGame(){
        walk();
        run();
        show();
        speak();
        sentence();
    }
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/344767.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号