/*
* DecisionsLoopLab.java
*
*/
//v3
package lab02;
import javax.swing.*;
public class DecisionsLoopLab {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String categoryStr; //Creates Category list; string type
String title; // Value entered by user; string type
String costStr; // Value entered by user; string type
String purchaseCostLevel; // Level of DVD purchses; string type
double cost; // The double form of the user-entered DVD cost
double discountPercent; // The double form of the dicounted percent
int totalPurchaseCost = 0; // Helps assign the level of purchase to the list
int resp = 0; // The user's response as to whether to continue
int dvdCounter = 0; // The number of DVDs the user has entered
int category = 0; // The user's number choice for the category
double total = 0; // The double form of the total of costs
// Initialize the output string to the empty string
String outputStr = "";
// Loop to input information on the user's DVD collection
while (true) {
// Read in DVD title from user as a string
title = JOptionPane.showInputDialog("Enter DVD title");
//Read in category from user as a number
categoryStr = JOptionPane.showInputDialog("Choose category by number \n1 Comedy "
+"\n 2 Drama \n 3 Action \n 4 Science Fiction "
+"\n 5 Animated");
//Convert from type String to type int
category = Integer.parseInt(categoryStr);
//Switch for the category
switch (category) {
case 1: categoryStr = ("Comedy"); break;
case 2: categoryStr = ("Drama"); break;
case 3: categoryStr = ("Action"); break;
case 4: categoryStr = ("Science Fiction"); break;
case 5: categoryStr = ("Animated"); break;
default: categoryStr = ("Invalid Category.");break;
}
// Convert from type string to type int
totalPurchaseCost = Integer.parseInt(purchaseCostLevel);
// If-else for purchseCostLevel
if (totalPurchaseCost == 0) {
if (total < 25)
purchaseCostLevel = "Low";
else if (total >= 25)
purchaseCostLevel = "Medium";
else if (total < 75)
purchaseCostLevel = "Medium";
else if (total >= 75)
purchaseCostLevel = "High";
else if (total <= 100)
purchaseCostLevel = "High";
else if (total >= 120)
purchaseCostLevel = "Very High";
}
//If-else for discountPercent
if (discountPercent == 0) {
if (total < 20)
discountPercent = total * 0.05;
else if (total >= 25)
discountPercent = total * 0.10;
else if (total < 75)
discountPercent = total * 0.10;
else if (total >= 75)
discountPercent = total * 0.15;
else if (total < 100)
discountPercent = total * 0.15;
else if (total >= 120)
discountPercent = total * 0.20;
}
// Read in cost from user as a string
costStr = JOptionPane.showInputDialog("Enter DVD cost");
// Convert from type String to type double
cost = Double.parseDouble(costStr);
// Keeps the count of DVDs
dvdCounter = dvdCounter + 1;
// Finding the total of the costs
total = cost + total;
// Add the user-entered values to the output string
outputStr = outputStr + "DVD " + dvdCounter + ", Cat: " + categoryStr + ", Title: " + title + ", ";
outputStr = outputStr + "Cost: " + cost + " Total: " + total + "Level:" + purchaseCostLevel + "\n";
outputStr = outputStr + "Level" + totalLevel +
// Get the user's choice as to whether to continue the loop
resp = JOptionPane.showConfirmDialog(null, outputStr + "\nContinue?", "Confirm",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
// Test whether the user's choice is to continue the loop or not
if (resp == JOptionPane.NO_OPTION)
break;
}
// Display final output to the user
JOptionPane.showMessageDialog(
null, outputStr, "Account Total", JOptionPane.INFORMATION_MESSAGE);
// System.exit( 0 ); // Terminate the program
}
}