| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 654 人关注过本帖
标题:这怎么修改啊?
只看楼主 加入收藏
床至只局
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2015-2-1
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
这怎么修改啊?
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package c8;
import java.util.Scanner;

/**
 *
 * @author lenovo
 */
class Dog{
    public void eat(){
        System.out.println("Dog eating");
    }
    public void eats(){
        System.out.println("Dogs eating");
    }
}
class Cat{
    public void eat(){
        System.out.println("Cat eating");
    }
    public void eats(){
        System.out.println("Cats eating");
    }
}
class Feeder{
    public void Feed(String animal="Dog"){
        int i;
        if(animal.equals("Dog")){
            i=1;
        }else if(animal.equals("Dogs")){
            i=2;
        }else if(animal.equals("Cat")){
            i=3;
        }else if(animal.equals("Cats")){
            i=4;
        }
        switch(i){
            case 1:
                Dog dog=new Dog();
                dog.eat();
                break;
            case 2:
                Dog dogs=new Dog();
                dogs.eats();
                break;
            case 3:
                Cat cat=new Cat();
                cat.eat();
                break;
            case 4:
                Cat cats=new Cat();
                cats.eats();
                break;
            default:
                System.out.println("please input Dog(s) or Cat(s):");
                Feeder feed=new Feeder();
                feed.Feed();
        }
    }
}
        
        
        
        
public class Feeding {
    public static void main(String[] args){
        Feeder feed=new Feeder();
        Scanner can=new Scanner();
        String an=can.next();
        feed.Feed(an);
    }
}
收到的鲜花
  • 林月儿2015-05-03 21:20 送鲜花  49朵   附言:good good study,day day up
搜索更多相关主题的帖子: package lenovo public change eating 
2015-05-02 23:09
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:10 
还是评论吧。。。字数还限制
import java.util.Scanner;

 class Dog{
    public void eat(){
        System.out.println("Dog eating");
    }
    public void eats(){
        System.out.println("Dogs eating");
    }
}
class Cat{
    public void eat(){
        System.out.println("Cat eating");
    }
    public void eats(){
        System.out.println("Cats eating");
    }
}
class Feeder{
    public void Feed(String animal){
        int i=0;
        if(animal.equals("Dog")){
            i=1;
        }else if(animal.equals("Dogs")){
            i=2;
        }else if(animal.equals("Cat")){
            i=3;
        }else if(animal.equals("Cats")){
            i=4;
        }
        switch(i){
            case 1:
                Dog dog=new Dog();
                dog.eat();
                break;
            case 2:
                Dog dogs=new Dog();
                dogs.eats();
                break;
            case 3:
                Cat cat=new Cat();
                cat.eat();
                break;
            case 4:
                Cat cats=new Cat();
                cats.eats();
                break;
            default:
                System.out.println("please input Dog(s) or Cat(s):");
                Feeder feed=new Feeder();
                String an=new Scanner(System.in).nextLine();
                feed.Feed(an);
        }
    }
}
        
        
        
        
public class Feeding {
    public static void main(String[] args){
        Feeder feed=new Feeder();
        Scanner can=new Scanner(System.in);
        String an=can.nextLine();
        feed.Feed(an);
    }
}

剑栈风樯各苦辛,别时冰雪到时春
2015-05-02 23:24
秦时的明月夜
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:13
帖 子:126
专家分:504
注 册:2013-3-12
收藏
得分:10 
程序代码:
import java.util.Scanner;
        
public class Feeding {
    public static void main(String[] args){
        Feeder feed=new Feeder();
        Scanner can=new Scanner(System.in);
        String an=can.next();
        feed.Feed(an);
    }
}
class Dog{
    public void eat(){
        System.out.println("Dog eating");
    }
    public void eats(){
        System.out.println("Dogs eating");
    }
}
class Cat{
    public void eat(){
        System.out.println("Cat eating");
    }
    public void eats(){
        System.out.println("Cats eating");
    }
}
class Feeder{
    public void Feed(String animal){
        int i = 0;
        if(animal.equals("Dog")){
            i=1;
        }else if(animal.equals("Dogs")){
            i=2;
        }else if(animal.equals("Cat")){
            i=3;
        }else if(animal.equals("Cats")){
            i=4;
        }
        switch(i){
            case 1:
                Dog dog=new Dog();
                dog.eat();
                break;
            case 2:
                Dog dogs=new Dog();
                dogs.eats();
                break;
            case 3:
                Cat cat=new Cat();
                cat.eat();
                break;
            case 4:
                Cat cats=new Cat();
                cats.eats();
                break;
            default:
                System.out.println("please input Dog(s) or Cat(s):");
                Feeder feed=new Feeder();
                feed.Feed(animal);
        }
    }
}

 //红色是修改的地方……给点分就行……
收到的鲜花
  • 林月儿2015-05-03 21:03 送鲜花  7朵  
2015-05-03 20:59
快速回复:这怎么修改啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040055 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved