-3

我正在为我的 CSE 20 课程做我的第一个项目,我必须编写一个简单的租车系统。我一开始就卡住了。我需要问车,# 天,然后你是否是俱乐部会员。如果您不是,代码需要继续并输出总数,它确实如此。但是,如果您是俱乐部会员,则必须询问有关行政一揽子计划的另一个问题,那么这会在总输出中增加另一条线。我不知道如何对其进行编码以完全运行。任何帮助,将不胜感激。

import java.util.Scanner;

public abstract class Bobcar1 {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    Scanner blah = new Scanner(System.in);
    System.out.println("Available cars: 1 for Econobox, 2 for Compact, 3 for Standard");
    System.out.print("Please choose the rental car: ");
    int car;
    car = blah.nextInt();
    System.out.print("Please enter the number of rental days: ");
    int day;
    day = blah.nextInt();
    System.out.print("Club member?: 1 for yes, 0 for no: ");
    int re;
    re = blah.nextInt();
    if (re == 1)
        System.out.print("Platinum Executive Package?: 1 for yes, 0 for no: ");
    int pack;
    pack = blah.nextInt();
    if (re == 0) then what do i code here to get the program to run through completely?

    if (car == 1)   {
            int car1;
            car1 = (25 * day);

                    System.out.println("Base: " + day + " day(s) for a Econobox @ $25 per day:      " + "+$" + car1);
                    if (pack == 0 && re == 0)       {
                    System.out.println();
                    System.out.println("Total Estimate for Rental:                  " + " $" + car1);
                    }
                    if (re == 1 && pack == 0)       {
                            int re1;
                            re1 = (day/5)*25;
                    System.out.println("Club Member Discount:                   " + "-$" + re1);
                            int total1r;
                            total1r = car1 - re1;
                    System.out.println();
                    System.out.println("Total Estimate for Rental:                  " + " $" + total1r);
                    }
                    if (pack == 1 && re == 1)       {
                            int pack1;
                            pack1 = (int) (car1*.20);
                    System.out.println("Platinum Executive Package:                 " + "+$" + pack1);     
                            int re1;
                            re1 = (day/5)*25;
                    System.out.println("Club Member Discount:                   " + "-$" + re1);
                            int total1;
                            total1 = car1 + pack1 - re1;
                            System.out.println("Total Estimate for Rental:                  " + " $" + total1);
                    }
    }
    if (car == 2)   {
            int car1;
            car1 = (55 * day);

                    System.out.println("Base: " + day + " day(s) for a Compact @ $55 per day:  " + "+$" + car1);
                    if (pack == 0 && re == 0)       {
                    System.out.println();
                    System.out.println("Total Estimate for Rental:                  " + " $" + car1);
                    }
                    if (re == 1 && pack == 0)       {
                            int re1;
                            re1 = (day/5)*55;
                    System.out.println("Club Member Discountt:                   " + "-$" + re1);
                            int total1r;
                            total1r = car1 - re1;
                    System.out.println();
                    System.out.println("Total Estimate for Rental:                  " + " $" + total1r);
                    }
                    if (pack == 1 && re == 1)       {
                            int pack1;
                            pack1 = (int) (car1* .20);
                    System.out.println("Platinum Executive Package:                 " + "+$" + pack1);     
                            int re1;
                            re1 = (day/5)*55;
                    System.out.println("Club Member Discount:                   " + "-$" + re1);
                            int total1;
                            total1 = car1 + pack1 - re1;
                            System.out.println("Total Estimate for Rental:                  " + " $" + total1);
                    }
    }
    if (car == 3)   {
            int car1;
            car1 = (100 * day);

                    System.out.println("Base: " + day + " day(s) for a Standard @ $100 per day:        " + "+$" + car1);
                    if (pack == 0 && re == 0)       {
                    System.out.println();
                    System.out.println("Total Estimate for Rental:                  " + " $" + car1);
                    }
                    if (re == 1 && pack == 0)       {
                            int re1;
                            re1 = (day/5)*100;
                    System.out.println("Return Customer Discount:                   " + "-$" + re1);
                            int total1r;
                            total1r = car1 - re1;
                    System.out.println();
                    System.out.println("Total Estimate for Rental:                  " + " $" + total1r);
                    }
                    if (pack == 1 && re == 1)       {
                            int pack1;
                            pack1 = (int) (car1*.20);
                    System.out.println("Platinum Executive Package:                 " + "+$" + pack1);     
                            int re1;
                            re1 = (day/5)*100;
                    System.out.println("Club Member Discount:                   " + "-$" + re1);
                            int total1;
                            total1 = car1 + pack1 - re1;
                            System.out.println("Total Estimate for Rental:                  " + " $" + total1);
    }

 }}}}
4

1 回答 1

0

您应该修改您的 OP(原始帖子)以包含您在评论中发布的问题。

如果您想要做的只是修改代码以仅在他们指定他们是俱乐部会员的情况下询问他们是否想要白金套餐,那么您需要修改您的代码,以便您仅在以下情况下读取来自扫描仪的输入你打印问题。

换句话说,将 {} 放在 if 语句块周围。这是最佳实践,即使对于 1 行语句块也是如此。

您目前拥有:

...
int re;
re = blah.nextInt();
if (re == 1)
    System.out.print("Platinum Executive Package?: 1 for yes, 0 for no: ");
int pack;
pack = blah.nextInt();
...

您可以像这样修改您的代码:

...
int pack;
int re = blah.nextInt();
if (re == 1) {
    System.out.print("Platinum Executive Package?: 1 for yes, 0 for no: ");
    pack = blah.nextInt();
}
...
于 2013-10-15T23:07:22.787 回答