1. 程式人生 > >java----入門收銀臺收款程式2.0

java----入門收銀臺收款程式2.0

import java.util.Scanner;
public class Demo {
	public static void main(String[] args) {
		System.out.println("收銀臺收款程式2.0");
		Scanner scan=new Scanner(System.in);
		System.out.println("請輸入商品單價:");
		double cost=scan.nextDouble();
		System.out.println("請輸入商品數量:");
		double number=scan.nextDouble
(); double money=cost*number; if (money<500){ System.out.println("未滿500不打折"); }else if(money>=500&&money<1000){ money=money*0.8; System.out.println("滿500打8折"); }else if(money>=1000){ money=money*0.6; System.out.println("滿1000打6折"); } System.out.println("應付金額:"+money); System.
out.println("實付金額:"); double net=scan.nextDouble(); double change=net-money; if(net>=money){ System.out.println("找零"+change); }else if(net<money){ double lack=money-net; System.out.println("您給的錢少了,還差"+lack+"元。"); } } }
import java.util.Scanner;
public class Demo1
{ public static void main(String[] args) { System.out.println("收銀臺收款系統2.0"); Scanner scan=new Scanner(System.in); System.out.println("請輸入單價:"); double unitprice=scan.nextDouble(); System.out.println("請輸入數量:"); double amount=scan.nextDouble(); System.out.println("請輸入金額:"); double money=scan.nextDouble(); double totalPrice=unitprice*amount; if(totalPrice>=500&&totalPrice<1000){ totalPrice*=0.8; } if(totalPrice>=1000){ totalPrice*=0.6; } if(totalPrice<=money){ double change=money-totalPrice; System.out.println("總價為:"+totalPrice+",找零:"+change); }else { System.out.println("您給的錢不夠,還差:"+(totalPrice-money)); } } }