What works: My project as it is now works great for quoting with applicable discounts.
What doesn't: The array code I tried to include. ALSO, I can't seem to figure out how to make it go to the array list display with the user enters "n" when asked if they want to get another quote, it just ends the program.
What I'm looking for: When the user chooses "n" when asked if they would like another quote, I would like to have a rectangle array list of the multiple quotes that shows them:
Shirt Cost Setup Fee Discount Total
I am brand new to Java so I hope I haven't bitten off more than I can chew. I tried reading ahead in our text and have gotten overwhelmed. Thank you for your help!!
import java.text.NumberFormat;
import java.util.Scanner;
public class HighOctaneApp {
public static void main(String[] args)
{
// display a welcome message
System.out.println("Welcome to the High Octane Quote Calculator");
System.out.println();
// perform 1 or more calculations
Scanner sc = new Scanner(System.in);
String choice = "y";
while (choice.equalsIgnoreCase("y"))
{
// get the input from the user
System.out.println("Please complete the following fields");
System.out.print("Enter customer type= New or Existing (n/e): ");
String customerType = sc.next();
double shirtQuantity = getDoubleWithinRange(sc,
"Enter Shirt Quantity: ", 0, 1000);
int colors = getColorWithinRange(sc,
"Enter number of Colors in Design ($20/color): ", 0, 8);
// get the discount percent
double discountPercent = getDiscountPercent(customerType, shirtQuantity);
// calculate the discount amount and total
double shirtCost = shirtQuantity * 7;
double discountAmount = shirtCost * discountPercent;
double subtotal = shirtCost - discountAmount;
int setupColor = colors * 20;
double Total = subtotal + setupColor;
// get the currency and percent formatters
NumberFormat currency = NumberFormat.getCurrencyInstance();
NumberFormat percent = NumberFormat.getPercentInstance();
percent.setMinimumFractionDigits(1);
// format the result as a single string
String results =
"Shirt Cost:\t"
+ currency.format(shirtCost) + "\n"
+ "Color Setup Fee:\t"
+ currency.format(setupColor) + "\n"
+ "Discount Amount:\t"
+ currency.format(discountAmount) + "\n"
+ "Current Total (includes applicable discounts):\t\t"
+ currency.format(Total) + "\n";
// print the results
System.out.println();
System.out.println("INITIAL QUOTE");
System.out.println(results);
// see if the user wants to calculate another quote
System.out.print("Would you like to quote another project? (y/n): ");
choice = sc.next();
System.out.println();
}
}
public static double getDouble(Scanner sc, String prompt)
{
boolean isValid = false;
double d = 0;
while (isValid == false)
{
System.out.print(prompt);
if (sc.hasNextDouble())
{
d = sc.nextDouble();
isValid = true;
}
else
{
System.out.println("Error! Invalid decimal value. Try again.");
}
sc.nextLine(); // discard any other data entered on the line
}
return d;
}
public static double getDoubleWithinRange(Scanner sc, String prompt,
double min, double max)
{
double d = 0;
boolean isValid = false;
while (isValid == false)
{
d = getDouble(sc, prompt);
if (d <= min) {
System.out.println(
"Error! Number must be greater than " + min + ".");
}
else if (d >= max) {
System.out.println(
"Error! Number must be less than " + max + ".");
}
else {
isValid = true;
}
}
return d;
}
public static int getInt(Scanner sc, String prompt)
{
boolean isValidInt = false;
int i = 0;
while (isValidInt == false)
{
System.out.print(prompt);
if (sc.hasNextInt())
{
i = sc.nextInt();
isValidInt = true;
}
else
{
System.out.println("Error! Invalid entry. Y/N only. Try again.");
}
sc.nextLine(); // discard any other data entered on the line
}
return i;
}
public static int getColorWithinRange(Scanner sc, String prompt,
int min, int max)
{
int i = 0;
boolean isValid = false;
while (isValid == false)
{
i = getInt(sc, prompt);
if (i <= min) {
System.out.println(
"Error! Number must be greater than " + min + ".");
}
else if (i >= max) {
System.out.println(
"Error! Number must be less than " + max + ".");
}
else {
isValid = true;
}
}
return i;
}
public static double calculateTotal(double subtotal, int setupColor){
double Total;
{
Total = (subtotal + setupColor);
}
return Total;
}
// a static method that that has two parameters: customer type and subtotal.
/**
*
* @param customerType
* @param shirtQuantity
* @return discountPercent
*/
public static double getDiscountPercent(String customerType, double shirtQuantity) {
double discountPercent = 0;
if (customerType.equalsIgnoreCase("E"))
{
if (shirtQuantity < 40) {
discountPercent = 0;
}
else if (shirtQuantity >= 40 && shirtQuantity < 100) {
discountPercent = .2;
}
else if (shirtQuantity >= 100) {
discountPercent = .3;
}
}
else if (customerType.equalsIgnoreCase("N"))
{
if (shirtQuantity < 40) {
discountPercent = 0.5;
}
else if (shirtQuantity >= 40 && shirtQuantity < 100) {
discountPercent = .25;
}
else if (shirtQuantity >= 100) {
discountPercent = .35;
}
}
return discountPercent;
}
}

New Topic/Question
Reply



MultiQuote





|