/*
* 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
double cost; // The double form of the user-entered DVD cost
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
// 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");
//Switch for the category
switch (category) {
case 1: System.out.println("Comedy"); break;
case 2: System.out.println("Drama"); break;
case 3: System.out.println("Action"); break;
case 4: System.out.println("Science Fiction"); break;
case 5: System.out.println("Animated"); break;
default: System.out.println("Invalid Category.");break;
}
// 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;
// Add the user-entered values to the output string
outputStr = outputStr + "DVD" + dvdCounter + "Cat:" + category + ", title: " + title + ", ";
outputStr = outputStr + "Cost: " + cost + "\n";
// 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
}
}