这边写一点小小的商店管理系统,目前暂时只有几个功能,之后的博客中会进行改进,现在先将就着看吧。而且写的都是一些很基础的东西,就算新手应该也看得懂
这边附上代码
import java.util.Scanner;
public class shop{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("welcome to our shop!");
System.out.println("press 1 to continue");
System.out.println("press 2 to over");
//判断进入或退出系统
while(true)
{
int a = in.nextInt();
if(a==2)
{
System.out.println("see you next time!");
break;
//退出循环
}
if(a!=1&&a!=2)
{
System.out.println("no found");
//不会退出循环,所以必须输入正确的指令才能进行下一步
}
if(a==1)
{
System.out.println("there are many kinds of objects");
System.out.println("press 1 and turn to vegetable");
System.out.println("press 2 and turn to fruit");
//商品的分类与进入
int b = in.nextInt();
if(b==1)
{
System.out.println("No1 is tomato and just cost 6$");
System.out.println("No2 is potato and just cost 8$");
System.out.println("if you want to buy,please enter zhe number of them in proper order though the number is zero.");
//商品信息与购买格式
int Numbertomato = in.nextInt();
int Numberpotato = in.nextInt();
System.out.printf("you buy %d tomato and cost %d$\n",Numbertomato,6*Numbertomato);
System.out.printf("you buy %d potato and cost %d$",Numberpotato,8*Numberpotato);
//购买总数及价格
break;
}
if(b==2)
{
System.out.println("No1 apple and just cost 10$");
System.out.println("No2 banana and just cost 4$");
System.out.println("if you want to buy,please enter zhe number of them in proper order though the number is zero.");
int Numberapple = in.nextInt();
int Numberbanana = in.nextInt();
System.out.printf("you buy %d apple and cost %d$\n",Numberapple,10*Numberapple);
System.out.printf("you buy %d banana and cost %d$",Numberbanana,4*Numberbanana);
break;
}
}
}
}
}