Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I can\'t figure out what I\'m doing wrong in the below scripting. In the section

ID: 3773626 • Letter: I

Question

I can't figure out what I'm doing wrong in the below scripting.

In the section that tests for   -    if (condoType == 1 || condoType == 2 || condoType == 3)
if it is false, it's not recognizing the else option unless I put the whole if section in brackets. But if I put it in brackets then it won't hold the value of parking.

import java.util.Scanner;
public class CondoSalesTest
{
public static void main(String[] args)
{

final double PARKVIEW_PRICE = 150000.00;
final double GOLFVIEW_PRICE = 170000.00;
final double LAKEVIEW_PRICE = 210000.00;
final double GARAGE_PRICE = 5000.00;
final double COUNTER_PRICE = 4000.00;
final double RUSH_PRICE = 2000.00;
final double PARKING_PRICE;
int condoType;
int counterType;
int parking;
int rushType;
double condoPrice;
double parkingPrice;
double counterPrice;
double rushPrice;
String message;
String counterMessage;
String rushMessage;
String parkingMessage;

Scanner input = new Scanner(System.in);
System.out.println("Please enter your condominium selection: 1 - Park View 2 - Golf " +
"Course View 3 - Lake View");
condoType = input.nextInt();

if (condoType == 1)
{
condoPrice = PARKVIEW_PRICE;
message = "park view";
}
else if (condoType == 2)
{
condoPrice = GOLFVIEW_PRICE;
message = "golf course view";
}
else if (condoType == 3)
{
condoPrice = LAKEVIEW_PRICE;
message = "lakeview";
}
else
{
condoPrice = 0;
message = "invalid";
}

System.out.println("Please enter your counter selection: 1 - Granite 2 - Standard");
counterType = input.nextInt();

if (counterType == 1)
{
counterPrice = COUNTER_PRICE;
counterMessage = "granite countertops";
}
else if (counterType == 2)
{
counterPrice = 0;
counterMessage = "standard countertops";
}
else
{
counterPrice = 0;
counterMessage = "invalid countertop selection";
}

System.out.println("Would you like your construction expedited? 1 - Yes (Additional $2000) 2 - No");
rushType = input.nextInt();

if (rushType == 1)
{
rushPrice = RUSH_PRICE;
rushMessage = "expedited construction";
}
else if (rushType == 2)
{
rushPrice = 0;
rushMessage = "non-expedited construction";
}
else
{
rushPrice = 0;
rushMessage = "invalid expedited selection";
}

if (condoType == 1 || condoType == 2 || condoType == 3)
{
System.out.println("Please select a parking space: 1 - Garage 2 - Parking Space: ");
parking = input.nextInt();
if (parking == 1)
{
parkingPrice = GARAGE_PRICE;
parkingMessage = "a garage";
}
else if (parking == 2)
{
parkingPrice = 0;
parkingMessage = "without a garage";
}
else
{
parkingPrice = 0;
parkingMessage = "invalid parking selection";
}
}
else
System.out.println("Garage choice not offered.");


System.out.println();
System.out.println("You entered: " + condoType + " for condo type " + counterType
+ " for counter type " + rushType + " for expedited construction "
+ parking + " for parking choice");
System.out.println();
System.out.println("You choose a " + message + " condo with:");
System.out.println(counterMessage);
System.out.println(rushMessage);
System.out.println("and " + parkingMessage);
System.out.println();
System.out.println("The total cost of your condo will be $" +
(condoPrice + counterPrice + rushPrice + parkingPrice));

}
}

Explanation / Answer

//suggestion commented and highlighted

import java.util.Scanner;

public class CondoSalesTest {

   public static void main(String[] args) {

       final double PARKVIEW_PRICE = 150000.00;

       final double GOLFVIEW_PRICE = 170000.00;

       final double LAKEVIEW_PRICE = 210000.00;

       final double GARAGE_PRICE = 5000.00;

       final double COUNTER_PRICE = 4000.00;

       final double RUSH_PRICE = 2000.00;

       final double PARKING_PRICE;

       int condoType;

       int counterType;

       int parking = 0;

       int rushType;

       double condoPrice;

       double parkingPrice = 0;

       double counterPrice;

       double rushPrice;

       String message;

       String counterMessage;

       String rushMessage;

       String parkingMessage = null;

       Scanner input = new Scanner(System.in);

       System.out

               .println("Please enter your condominium selection: 1 - Park View 2 - Golf "

                       + "Course View 3 - Lake View");

       condoType = input.nextInt();

       if (condoType == 1) {

           condoPrice = PARKVIEW_PRICE;

           message = "park view";

       } else if (condoType == 2) {

           condoPrice = GOLFVIEW_PRICE;

           message = "golf course view";

       } else if (condoType == 3) {

           condoPrice = LAKEVIEW_PRICE;

           message = "lakeview";

       } else {

           condoPrice = 0;

           message = "invalid";

       }

       System.out

               .println("Please enter your counter selection: 1 - Granite 2 - Standard");

       counterType = input.nextInt();

       if (counterType == 1) {

           counterPrice = COUNTER_PRICE;

           counterMessage = "granite countertops";

       } else if (counterType == 2) {

           counterPrice = 0;

           counterMessage = "standard countertops";

       } else {

           counterPrice = 0;

           counterMessage = "invalid countertop selection";

       }

       System.out

               .println("Would you like your construction expedited? 1 - Yes (Additional $2000) 2 - No");

       rushType = input.nextInt();

       if (rushType == 1) {

           rushPrice = RUSH_PRICE;

           rushMessage = "expedited construction";

       } else if (rushType == 2) {

           rushPrice = 0;

           rushMessage = "non-expedited construction";

       } else {

           rushPrice = 0;

           rushMessage = "invalid expedited selection";

       }

       if (condoType == 1 || condoType == 2 || condoType == 3) {

           System.out

                   .println("Please select a parking space: 1 - Garage 2 - Parking Space: ");

           // since you are taking parking option inside if statement,parking

           // variable will get value here only and not in else statement if condoType is not 1,2 or 3,parking variable will have first initialized value

           parking = input.nextInt();

           if (parking == 1) {

               parkingPrice = GARAGE_PRICE;

               parkingMessage = "a garage";

           } else if (parking == 2) {

               parkingPrice = 0;

               parkingMessage = "without a garage";

           } else {

               parkingPrice = 0;

               parkingMessage = "invalid parking selection";

           }

       } else

           System.out.println("Garage choice not offered.");

       System.out.println();

       System.out.println("You entered: " + condoType + " for condo type "

               + counterType + " for counter type " + rushType

               + " for expedited construction " + parking

               + " for parking choice");

       System.out.println();

       System.out.println("You choose a " + message + " condo with:");

       System.out.println(counterMessage);

       System.out.println(rushMessage);

       System.out.println("and " + parkingMessage);

       System.out.println();

       System.out.println("The total cost of your condo will be $"

               + (condoPrice + counterPrice + rushPrice + parkingPrice));

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote