第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

電影票計算

電影票計算

蕪湖不蕪 2022-11-02 10:04:07
在多廳影院,宣布了一項折扣計劃,當(dāng)批量預(yù)訂超過 20 張門票時,可享受門票總價 10% 的折扣,如果有 20 張票,則可享受門票總價的 2% 折扣。提交特殊優(yōu)惠券。制定一個程序,以根據(jù)該計劃找到總成本。國王艙票價為 75 盧比,皇后艙票價為 150 盧比。也可以通過支付額外的盧比來選擇茶點。每個會員 50 個。提示:k-king 和 q-queen,您必須同時預(yù)訂最少 5 張門票,最多 40 張門票。如果失敗,則顯示“最少 5 張,最多 40 張票”。如果 circle 被賦予除“k”或“q”以外的值,則輸出應(yīng)為“無效輸入”。票價應(yīng)精確打印到小數(shù)點后兩位。示例輸入 1:輸入票號:35是否要茶點:y是否有優(yōu)惠券代碼:y輸入圓圈:k示例輸出 1:門票成本:4065.25示例輸入 2:輸入票號:1樣本輸出 2:最少 5 張,最多 40 張票這是代碼import java.util.Scanner;import java.text.DecimalFormat;public class CinemaTicket {    public static void main(String[] args) {        int no, refe, total = 0;        double cost, sum, sum1, sum2, sum3;        String ref, co, circle;        Scanner s = new Scanner(System.in);        System.out.println("Enter the no of ticket:");        no = s.nextInt();        if (no < 5 || no > 40) {            System.out.println("Minimum of 5 and Maximum of 40 tickets");        }        System.out.println("Do you want refreshment:");        ref = s.next();        System.out.println("Do you have a coupon code:");        co = s.next();        System.out.println("Enter the circle:");        circle = s.next();        if (circle == "k") {            total = no * 75;        } else if (circle == "q") {            total = no * 150;        } else {            System.out.println("Invalid Input");        }        if (no > 20) {            sum = ((0.1) * total);            sum1 = total - sum;            if (co == "y") {                sum2 = ((0.2) * total);                sum3 = sum1 - sum2;                if (ref == "y") {                    refe = no * 150;                    cost = sum3 + refe;                } else {                    cost = sum3;                }            } else {                cost = sum1;            }        } else {            cost = total;        }        DecimalFormat df = new DecimalFormat("#.##");        System.out.println("Ticket cost:" + df.format(cost));    }} 我試過這段代碼,但它沒有計算機(jī)票的成本。
查看完整描述

2 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗 獲得超2個贊

使用 String 方法 equals() 或 compareTo()。邏輯運(yùn)算符不會比較 java 中的字符串,因為它不是原始類型。



查看完整回答
反對 回復(fù) 2022-11-02
?
慕娘9325324

TA貢獻(xiàn)1783條經(jīng)驗 獲得超4個贊

您需要做的就是:


if (circle.equals("k")) {

            total = no * 75;

        } else if (circle.equals("q")) {

            total = no * 150;

        } else {

            System.out.println("Invalid Input");

        }

不要使用“==”,使用 equals 方法,它會正常工作。


查看完整回答
反對 回復(fù) 2022-11-02
  • 2 回答
  • 0 關(guān)注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號