天天看點

java初學者的第一個程式

/**
*
*/
        
public class Shopping {
    public static void main(String [] args) {
        System.out.println("\t\t歡迎使用我行我素管理系統1.0版");
        System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
        System.out.println("\t\t\t1.登入系統");
	System.out.println("\t\t\t2.更改管理者密碼");
	System.out.println("\t\t\t3.退出");
	System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
        System.out.print("請輸入您的選擇:");
	java.util.Scanner input = new java.util.Scanner(System.in);
	int choice1 = input.nextInt();
       	if(choice1 == 1){
		System.out.println("\t\t歡迎使用我行我素管理系統");
		System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
		System.out.println("\t\t\t1.客戶資訊管理");
		System.out.println("\t\t\t2.購物結算");
		System.out.println("\t\t\t3.真情回饋");
		System.out.println("\t\t\t4.傳回上一級");
		System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
		System.out.print("請輸入您的選擇:");
		//java.util.Scanner input = new java.util.Scanner(System.in);
		int choice2 = input.nextInt();
		if(choice2 == 2){
			System.out.println("商城現有商品如下:");
		        System.out.println("商品編号\t\t商品名稱\t\t商品價格");
			System.out.println("1\t\t\t雲南白藥\t\t¥18.00");
			System.out.println("2\t\t\t小米手機\t\t¥1,998.00");
			System.out.println("3\t\t\t小黑\t\t\t¥4,998.00");              
                        System.out.println("4\t\t\t拖鞋\t\t\t¥25.80");
			System.out.println("5\t\t\t醬油\t\t\t¥5.60");
			System.out.println("6\t\t\t汽車模型\t\t¥350.00");
			System.out.println("7\t\t\t坦克模型\t\t¥400.00");
			System.out.println("8\t\t\t玩具槍\t\t¥99.80");
			System.out.print("請輸入您要購買的産品編号:");
			//java.util.Scanner input = new java.util.Scanner(System.in);
			int choice3 = input.nextInt();
			System.out.print("請輸入您要購買的産品數量:");
			//java.util.Scanner input = new java.util.Scanner(System.in);
			int choice4 = input.nextInt();
			double sum = 0;
			double a = 0;
			String str = "輸入錯誤";
			switch (choice3) {
			    case 1:
				sum = choice4 * 18;
				a = 18;
				str = "雲南白藥";
				break;
			    case 2:
				sum = choice4 * 1998;
				a = 1998;
				str = "小米手機";
				break;
			    case 3:
				sum = choice4 * 4998;
				a = 4998;
				str = "小黑";
				break;
			    case 4:
				sum = choice4 * 25.8;
				a = 25.8;
				str = "拖鞋";
				break;
			    case 5:
				sum = choice4 * 5.6;
				a = 5.6;
				str = "醬油";
				break;
			    case 6:
				sum = choice4 * 350;
				a = 350;
				str = "汽車模型";
				break;
			    case 7:
				sum = choice4 * 400;
				a = 400;
				str = "坦克模型";
				break;
			    case 8:
				sum = choice4 * 99.8;
				a = 99.8;
				str = "玩具槍";
				break;   
			    default:
				break;
			}
			System.out.println("尊敬的使用者:小貓");
			System.out.println("産品名稱\t\t産品單價\t\t購買數量");
			System.out.println(str + "\t\t" + a +"\t\t\t" + choice4);
			System.out.println("您購買的産品總價為:¥" + sum);
			System.out.println("按您目前的積分,您的折扣是:0.85");
			double b;
			b = 0.85 * sum;
			System.out.println("您的應付款為:¥" + (float)b);
			System.out.print("請付款:");
			//java.util.Scanner input = new java.util.Scanner(System.in);
			int num = input.nextInt();
			if(num < sum){
			    System.out.println("系統拒絕,請重新寵幸本系統!");
			} else {
			    System.out.println("付款成功!");
			    System.out.println("找零:¥" + (float)(num - b));
			    System.out.println("歡迎下次光臨!");
			}
		} else {
		    System.out.println("功能正在更新中.........");
		}
        } else {
	    System.out.println("功能正在更新中.........");
        }
    }
}    
           
java初學者的第一個程式

繼續閱讀