需求: 購買物品 並且顯示 可以找零多少
物品價格 : 1.led 單價 4999元
2.RAM 單價 1280元
3.Mouse 單價 699元
特價: 超過五萬 或是 是會員 都打 95折
題目內容:
import java.util.Scanner;
class ex2
{
public static void main(String args[])
{
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.println("你好請先選購商品.超過5萬打95折,是會員在打95折");
System.out.println("1.led 單價 4999元\n2.RAM 單價 1280元\n3.Mouse 單價 699元\n請選購:\n");
int a,b,c,dd,ww;
String gg;
double hj,cf,ok;
a = 4999;
b = 1280;
c = 699;
Scanner in = new Scanner(System.in);
String k;
char j;
System.out.println("要購買幾個 led 單價 4999元:");
a= sc.nextInt();
System.out.println("要購買幾個 RAM 單價 1280元:");
b= sc.nextInt();
System.out.println("要購買幾個 Mouse 單價 699元:");
c= sc.nextInt();
dd = (a*4999) + (b*1280) + (c*699);
System.out.println("消費金額為"+dd);
if(dd >50000)
{
System.out.println("您花費超過5萬,享有打95折優惠");
hj = dd * 0.95; //超過五萬打折
System.out.println("價格調整為:"+hj);
}
System.out.println("請問是否為會員,y/n");
//k = in.next();
//j = k.charAt(0);
while(true)
{
k = in.next();
j = k.charAt(0);
if ( j ==121)
{
System.out.println("您是會員價,將享有價格優惠");
cf= dd * 0.95; //會員價格
System.out.println("價格調整為:"+cf);
ok = cf;
break;
}
else if ( j ==110)
{
System.out.println("很抱歉不是會員,加入會員享有95折");
ok = dd;
break;
}
else
{
System.out.println("輸入無效,請輸入y/n");
}
}
System.out.println("結帳,您的消費金額為"+ok+"元");
System.out.println("請輸入您的付款金額");
int rr;
double uy;
while(true)
{
rr= sc.nextInt();
uy = rr -ok;
if(uy > 0)
{
System.out.println("您的付款金額為"+rr+"扣除消費總額為"+(int)ok+"\n剩餘"+(int)uy);
break;
}
else
{
System.out.println("輸入金額不足,請再次輸入");
}
}
double kcc,wcc,bcc,scc,gcc;
kcc = uy / 1000;
wcc = (uy % 1000) /500 ;
bcc = ((uy % 1000) %500) /100 ;
scc =(((uy % 1000) %500)%100) / 10 ;
gcc = ((((uy % 1000) %500)%100)%10) / 1 ;;
System.out.println("為您轉換零錢"+(int)kcc+"張千元,"+(int)wcc+"張五百元,"+(int)bcc+"張百元,"+(int)scc+"個十元硬幣跟"+(int)gcc+"個一元硬幣");
/*
System.out.println("========================找零========================");
double kcc,wcc,bcc,scc,gcc;
double ck, cw, cb, cs, cg;
if (uy >= 1000 )
{
kcc = (int)uy / 1000 ;
ck = uy-(kcc*1000) ;
wcc = (int)ck / 500 ;
cw = ck-(wcc*500) ;
bcc = (int)cw / 100 ;
cb = cw-(bcc*100) ;
scc = (int)cb / 10 ;
cs = cb-(scc*10) ;
gcc = cs / 1;
System.out.println("為您轉換零錢"+(int)kcc+"張千元,"+(int)wcc+"張五百元,"+(int)bcc+"張百元,"+(int)scc+"個十元硬幣跟"+(int)gcc+"個一元硬幣");
}
else if (uy >= 500 )
{
wcc = (int)uy / 500 ;
cw = uy-(wcc*500) ;
bcc = (int)cw / 100 ;
cb = cw-(bcc*100) ;
scc = (int)cb / 10 ;
cs = cb-(scc*10) ;
gcc = cs / 1;
System.out.println("為您轉換零錢"+(int)wcc+"張五百元,"+(int)bcc+"張百元,"+(int)scc+"個十元硬幣跟"+(int)gcc+"個一元硬幣");
}
else if (uy >= 100 )
{
bcc = (int)uy / 100 ;
cb = uy-(bcc*100) ;
scc = (int)cb / 10 ;
cs = cb-(scc*10) ;
gcc = cs / 1;
System.out.println("為您轉換零錢"+(int)bcc+"張百元,"+(int)scc+"個十元硬幣跟"+(int)gcc+"個一元硬幣");
}
else if (uy >= 10 )
{
scc = (int)uy / 10 ;
cs = uy-(scc*10) ;
gcc = cs / 1;
System.out.println((int)scc+"個十元硬幣跟"+(int)gcc+"個一元硬幣");
}
else
{
gcc = uy / 1;
System.out.println("為您轉換零錢"+(int)gcc+"個一元硬幣");
}
*/
/*
else
{
System.out.println("99999888885665454654");
}
*/
/*
System.out.println("===="+uy);
kcc = uy % 1000;
System.out.println("===="+kcc);
wcc = kcc % 500;
bcc = wcc % 100;
scc = bcc % 10;
gcc = scc % 1;
*/
//System.out.println("為您轉換零錢"+kcc+"張千元,"+wcc+"張五百元,"+bcc+"張百元,"+scc+"個十元硬幣跟"+gcc+"個一元硬幣");
}
}
執行結果:
請問這位同學,你是我哪一梯的學生
回覆刪除我是江老師
回覆刪除