电子狗类:
public class 电子狗 {
public int ghostpill=1;
public int grade;
public int happy;
public int talent;
public int hungry;
public int clear;
public int health;
//2个构造器
public 电子狗(){
grade=0;
happy=50;
talent=0;
hungry=50;
clear=50;
health=100;
}
public 电子狗(int g,int ha,int t,int hu,int c,int he){
grade=g;
happy=ha;
talent=t;
hungry=hu;
clear=c;
health=he;
}
public void printHead(){
System.out.println("欢迎来到电子狗窝~O(∩_∩)O~");
System.out.println("狗狗昵称:春狗");
System.out.println("主人:春熊");
System.out.println("主人的邮箱:conmajia@163.com");
}
public void printState(){
System.out.println("等级:"+grade);
System.out.println("快乐:"+happy);
System.out.println("智商:"+talent);
System.out.println("饥饿:"+hungry);
System.out.println("清洁:"+clear);
System.out.println("健康:"+health);
}
public void play(){
happy+=5;
talent+=2;
hungry-=5;
clear-=2;
health+=5;
grade+=1;
System.out.println("主人~我今天玩得好开心丫~");
System.out.println("(你的狗狗:等级上升1点、快乐上升5点、智商上升2点、饥饿下降5点、清洁下降2点、健康上升5点)");
}
public void learn(){
happy+=2;
talent+=5;
hungry-=2;
grade+=5;
System.out.println("主人~我今晚要挑灯夜战,横扫浙大图书馆的所有Java书!");
System.out.println("(你的狗狗:等级上升5点、快乐上升2点、智商上升5点、饥饿下降2点)");
}
public void wash(){
happy+=5;
clear+=15;
health+=5;
System.out.println("主人~玩水真爽~真希望天天过泼水节~O(∩_∩)O哈哈~!");
System.out.println("(你的狗狗:快乐上升5点、清洁上升15点、健康上升5点)");
}
public void inject(){
happy-=10;
health+=20;
System.out.println("555~~~~主人~打针好痛~~~~~~~再也不要来医院了!");
System.out.println("(你的狗狗:快乐下降10点、健康上升20点)");
}
public void pill(){
happy-=5;
health+=15;
System.out.println("主人~这药好苦~下次记得买水果口味的脑黄金~(*^__^*)嘻嘻……");
System.out.println("(你的狗狗:快乐下降5点、健康上升15点)");
}
public void ghost(){
if(ghostpill>0){
happy+=1000;
hungry+=1000;
health+=1000;
clear+=1000;
ghostpill--;
System.out.println("主人!我复活啦!哇哈哈!想死我了吧!呼呼(~ o ~)~zZ");
System.out.println("(你的狗狗:快乐上升1000点、饥饿上升1000点、清洁上升1000点、健康上升1000点)");
}
else{
System.out.println("很遗憾~你的还魂丹已经用完了~");
}
}
public void shopping(){
happy+=20;
hungry-=10;
clear-=5;
System.out.println("沃尔玛的东西真多~眼都看花了我~~~~~~呼呼(~ o ~)~zZ");
System.out.println("(你的狗狗:快乐上升20点、饥饿下降10点、清洁下降5点)");
}
}
StartPet类:
import java.util.*;
public class StartPet {
static int choice;
public static void main(String[] args){
电子狗 myPet=new 电子狗();
myPet.printHead();
while(true)
{
printChoice();
doChoice(choice,myPet);
}
}
static void printChoice(){
Scanner in=new Scanner(System.in);
System.out.println("--------------------------------------------------");
System.out.println("请选择:");
// System.out.println("1.状态");
// System.out.println("2.玩耍");
// System.out.println("3.洗澡");
// System.out.println("4.打针");
// System.out.println("5.吃药");
// System.out.println("6.购物");
System.out.println("1.状态 2.玩耍 3.洗澡 4.打针 5.吃药 6.购物 7.学习 8.还魂丹");
System.out.println("--------------------------------------------------");
choice=in.nextInt();
}
static void doChoice(int choice,电子狗 myPet){
switch(choice){
case 1:
myPet.printState();
break;
case 2:
myPet.play();
break;
case 3:
myPet.wash();
break;
case 4:
myPet.inject();
break;
case 5:
myPet.pill();
break;
case 6:
myPet.shopping();
break;
case 7:
myPet.learn();
break;
case 8:
myPet.ghost();
break;
default:
break;
}
}
}
追问大哥,好多红线啊。。。
运行后出现:
java.lang.NoSuchMethodError: main
Exception in thread "main"