import java.util.Scanner;
//大象类
class DaXiang{
boolean comin;
boolean close;
//把大象装进冰箱,在冰箱门打开以后。
public void comIn(boolean comin){
if(comin==true){
System.out.println("我是大象,冰箱门打开了,我该被装进冰箱了!\n");
}
else{
System.out.println("亲,想让我进去,也得打开冰箱门!\n");
}
}
//关闭冰箱门。
//public void close
}
//创建冰箱类
class Fridge{
boolean open;
//打开冰箱门
public void openFridge(boolean ope){
open=ope;
DaXiang dx=new DaXiang();
dx.comin=open;
System.out.println("冰箱门已经打开,请把大象装进冰箱。\n");
}
//关闭冰箱门
public void closeFridge(){
if(open==true){
System.out.println("要关门了,请查看冰箱里是否有大象\n");
}else{
System.out.println("表要逗我玩,冰箱门没开\n");
}
}
}
class Game1{
public static void main(String []args){
int i,j;
operate();
System.out.println("是否继续玩耍:1:继续,2:否");
Scanner sc = new Scanner(System.in);
i=sc.nextInt();
if(i==1){
operate();
}else if(i==2){
System.out.println("点右上角吧,不懂java的强制退出函数");
}else{
System.out.print("自曝倒计时:");
for(j=3;j>0;j--){
System.out.print(j);
}
}
}
public static void operate(){
System.out.println("把大象装冰箱分三步:");
System.out.println("1:打开冰箱门");
System.out.println("2:把大象放进去");
System.out.println("3:关上冰箱门\n");
int i;
Scanner sc = new Scanner(System.in);
i=sc.nextInt();
Fridge f =new Fridge();
DaXiang dx2 =new DaXiang();
System.out.println("请选择操作(1~3):\n");
switch(i){
case 1: f.openFridge(true);operate();break;
case 2: dx2.comIn(true);operate();break;
case 3: f.closeFridge();operate();break;
}
}
public static void read()
{
int i,j;
System.out.println("还想循环玩吗,1:继续,2:否");
Scanner sc = new Scanner(System.in);
i=sc.nextInt();
if(i==1){
operate();
}else if(i==2){
System.out.println("点右上角吧,不懂java的强制退出函数");
}else{
System.out.print("自曝倒计时:");
for(j=3;j>0;j--)
System.out.print(j);
}
}
}
虽然代码很简单,但还是希望不要拍砖,给点鼓励。初学者不易。 |