This is the assignment I have done most of it and am currently stuck on my last
ID: 3831304 • Letter: T
Question
This is the assignment I have done most of it and am currently stuck on my last if else statement. Halfway through these statements it cant find my totalCost variable.
IST Programming Challenge #1 - Cost Estimator (75 points)
1. Start a new Java Project and class file named after the program task with your initials (i.e.- CostEstimator_MH)
2. The user will be given a choice of 5 items as shown below (also shown is the price and weight): A) Router $1495.50 3 pounds B) Switch $695.50 3 pounds C) 100 Ft Cat 5 $99.99 5 pounds D) NIC $49.95 1 pound E) Patch Cable $9.95 1 pound
3. User will be asked to select A-E for the item, upper or lower case should be allowed.
4. Based on the selection using the switch-case structure, store the name of the item in a variable, the price in another and the weight in yet another. If none of the correct choices are made, exit the program.
5. The user will enter the quantity.
6. Calculate the extended Cost (quantity x cost). Calculate the total weight (quantity x weight).
7. Based on the quantity, calculate a discount amount (discount x extended cost), and sub-total (extended cost – discount amount) using the following:
a. < 10 items, no discount
b. 10-25 items, 10% discount
c. > 25 items, 15% discount
8. Ask if they are in Illinois. If yes, calculate a 6.25% sales tax. If no, 0%. The state tax should be in your code as a constant grouped with the variables. Install an “Easter Egg” – If the user enters jAvA (exact case) for the answer, make the total cost $1.00.
9. If the total cost of merchandise is over $1000, free shipping. If not over $1000, the shipping cost is $10 + $2 per pound, so that ordering 2 switches would cost $10 + ($2 x 6 lbs) = $22.
10. Calculate the final cost.
11. Display all data for the purchaser that would be of interest to them to verify costs.
Notes:
• You may use Scanner or Dialogs for user input/output.
• Ensure you validate all possible options – items, costs, discounts, etc, to ensure they all work correctly with different amounts, etc.
• Format all dollar amounts to 2 decimal places, with dollar signs.
• Submitting code with errors that prevent it from running (syntax errors) will result in grade of 0.
• Logical errors or missing functionality or comments will lose points based on how much is wrong.
• Late submissions will result in a loss of 10% per week day (even over break).
• There should be sufficient comments to explain what the code is doing at each stage.
Grading: Correct Operation 40 points Variable/Naming Conventions: 10 points Commenting 15 points User Friendliness 10 points
DUE: By start of class, Thursday, March 9th. Chapter 3 online Quiz also due before start of class (once released). Midterm exam will be that day. After the exam, if no other classes, you may start Spring Break
Here is my code so far.
import java.util.Scanner;
public class CostEstimator_ND {
public static void main(String[] args)
{
// Declare variables
String
input,
input2,
product,
promo,
promoCode;
double
productPrice = 0,
productWeight = 0,
quantity,
extendedCost,
totalWeight,
shippingWeight,
discountExtendedCost,
salesTax = 0;
final double TAX = 6.25,
totalCost;
char
choice,
answer;
System.out.println("Please choose a letter of choice");
System.out.println("A) Router $1495.50 3 pounds");
System.out.println("B) Switch $695.50 3 pounds");
System.out.println("C) 100 Ft CAT 5 $99.99 5 pounds");
System.out.println("D) NIC $49.95 1 pound");
System.out.println("E) Patch Cable $9.95 1 pound");
Scanner keyboard = new Scanner(System.in);
//input.nextLine(); to clear
input = keyboard.nextLine();
choice = input.charAt(0);
switch (choice)
{
case 'A':
case 'a':
product = "Router";
productPrice = 1495.50;
productWeight = 3;
break;
case 'B':
case 'b':
product = "Switch";
productPrice = 695.50;
productWeight = 3;
break;
case 'C' :
case 'c' :
product = "100 Ft Cat 5";
productPrice = 99.99;
productWeight = 5;
break;
case 'D' :
case 'd' :
product = "NIC";
productPrice = 49.95;
productWeight = 1;
break;
case 'E' :
case 'e' :
product = "Patch Cable";
productPrice = 9.95;
productWeight = 1;
break;
default:
System.out.println("Invalid Entry");
System.exit(0);
break;
}
System.out.println("Please enter quantity of product");
quantity = keyboard.nextInt();
extendedCost = quantity * productPrice;
totalWeight = quantity * productWeight;
if (quantity < 10)
discountExtendedCost = productPrice;
else if (quantity > 10 && quantity < 25)
discountExtendedCost = productPrice / 10;
else if (quantity > 25)
discountExtendedCost = productPrice / 15;
keyboard.nextLine();
Scanner keyboard2 = new Scanner(System.in);
System.out.println("Do you live in Illinois? Y/N?");
input2 = keyboard.nextLine();
answer = input2.charAt(0);
switch (answer)
{
case 'Y' :
case 'y' :
salesTax = productPrice / TAX;
break;
case 'N' :
case 'n' :
salesTax = 0;
break;
default :
System.out.println("Please choose correct entry.");
break;
}
System.out.println("What program language is this written in?");
promo = keyboard.nextLine();
promoCode = "jAvA";
if (promo == promoCode)
totalCost = 1.00;
else if (promo != promoCode)
totalCost = extendedCost + salesTax;
else if (totalCost < 1000)
{
totalCost += 10;
shippingWeight = totalWeight * 2;
totalCost += shippingWeight;
}
}
}
Explanation / Answer
import java.util.Scanner;
public class CostEstimator_ND {
public static void main(String[] args)
{
// Declare variables
String input, input2, product = " ", promo, promoCode;
double productPrice = 0, productWeight = 0, quantity, extendedCost, totalWeight, shippingWeight, discountExtendedCost=0, salesTax = 0, totalCost=0;
final double TAX = 6.25;
char choice, answer;
System.out.println("Please choose a letter of choice");
System.out.println("A) Router $1495.50 3 pounds");
System.out.println("B) Switch $695.50 3 pounds");
System.out.println("C) 100 Ft CAT 5 $99.99 5 pounds");
System.out.println("D) NIC $49.95 1 pound");
System.out.println("E) Patch Cable $9.95 1 pound");
Scanner keyboard = new Scanner(System.in);
//input.nextLine(); to clear
input = keyboard.nextLine();
choice = input.charAt(0);
switch (choice)
{
case 'A': case 'a':
product = "Router";
productPrice = 1495.50;
productWeight = 3;
break;
case 'B': case 'b':
product = "Switch";
productPrice = 695.50;
productWeight = 3;
break;
case 'C' : case 'c' :
product = "100 Ft Cat 5";
productPrice = 99.99;
productWeight = 5;
break;
case 'D' : case 'd' :
product = "NIC";
productPrice = 49.95;
productWeight = 1;
break;
case 'E' : case 'e' :
product = "Patch Cable";
productPrice = 9.95;
productWeight = 1;
break;
default:
System.out.println("Invalid Entry");
System.exit(0);
break;
}
System.out.println("Please enter quantity of product");
quantity = keyboard.nextInt();
extendedCost = quantity * productPrice;
totalWeight = quantity * productWeight;
if (quantity < 10)
discountExtendedCost = extendedCost;
else if (quantity > 10 && quantity < 25)
discountExtendedCost = extendedCost - extendedCost/10; //calculating cost of product after discount
else if (quantity > 25)
discountExtendedCost = extendedCost - ((extendedCost * 15)/100);
keyboard.nextLine();
Scanner keyboard2 = new Scanner(System.in);
System.out.println("Do you live in Illinois? Y/N?");
input2 = keyboard.nextLine();
answer = input2.charAt(0);
switch (answer)
{
case 'Y' : case 'y' :
salesTax = (discountExtendedCost * TAX)/100; //calculating sales tax on discountExtendedCost
break;
case 'N' : case 'n' :
salesTax = 0;
break;
default :
System.out.println("Please choose correct entry.");
break;
}
System.out.println("What program language is this written in?");
promo = keyboard.nextLine();
promoCode = "jAvA";
if (promo.equals(promoCode))
totalCost = 1.00;
else if (!promo.equals(promoCode))
{
totalCost = discountExtendedCost + salesTax;
if(totalCost < 1000)
{
totalCost += 10;
shippingWeight = totalWeight * 2;
totalCost += shippingWeight;
}
}
System.out.println("Your total cost for product " + product + " with quantity " + quantity + " is: ");
System.out.println("Total product cost: " + extendedCost);
System.out.println("Discount: " + (extendedCost - discountExtendedCost));
System.out.println("Sales Tax: " + salesTax);
System.out.println("Total cost with or without shipping cost: " + totalCost);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.