My final consists of taking my first test and adding in decision statements and loops. I'm assuming he wants it to run as if you're making multiple transactions and at the end of the day you're going to sum them all up (POS system?).
Here's the initial code from the first test:
/* This is a program that will take customers input and create a receipt */
import javax.swing.JOptionPane;
public class CrescentCityEats
{
public static void main(String args[])
{
// Declare variables
String coffeeSoldString;
String hurricaneSoldString;
String beignetSoldString;
double coffeePrice = 3.95;
double hurricanePrice = 8.95;
double beignetPrice = 2.95;
double salesTax = .09;
int coffeeSold;
int hurricaneSold;
int beignetSold;
double coffeeSales;
double hurricaneSales;
double beignetSales;
double subTotalSales;
double totalSalesTax;
double totalSales;
// Get input
coffeeSoldString = JOptionPane.showInputDialog("Enter How Many Chickory Coffee Sold: ");
hurricaneSoldString = JOptionPane.showInputDialog("Enter How Many Hurricanes Sold: ");
beignetSoldString = JOptionPane.showInputDialog("Enter How Many Beignets Sold: ");
// Convert input to correct data type
coffeeSold = Integer.parseInt(coffeeSoldString);
hurricaneSold = Integer.parseInt(hurricaneSoldString);
beignetSold = Integer.parseInt(beignetSoldString);
// All Calculations go in the below sections
// Figure coffee sales
coffeeSales = coffeeSold * coffeePrice;
// Figure hurricane sales
hurricaneSales = hurricaneSold * hurricanePrice;
// Figure beignet sales
beignetSales = beignetSold * beignetPrice;
// Figure sub-total sales
subTotalSales = coffeeSales + hurricaneSales + beignetSales;
// figure out sales tax on the purchase
totalSalesTax = salesTax * subTotalSales;
// figure out total sales of purchase
totalSales = subTotalSales + totalSalesTax;
// receipt output
System.out.println("\tFat Tuesday Eats\n");
System.out.println(coffeeSold +"\tChicory Coffee\t"+coffeeSales);
System.out.println(hurricaneSold +"\tHurricane\t"+hurricaneSales);
System.out.println(beignetSold +"\tBeignet\t\t"+beignetSales);
System.out.println("\tSubtotal\t"+subTotalSales);
System.out.println("\tSales Tax\t"+totalSalesTax);
System.out.println("\tTotal\t\t"+totalSales);
System.exit(0);//End the method
}//close the method
}//close the class
Here's what I've done so far, it's now a loop allowing you to calculate another transaction:
/* This is a program that will take customers input and create a receipt */
import javax.swing.JOptionPane;
public class FINALpossibilitiesRETRY
{
public static void main(String args[])
{
// Declare variables
String coffeeSoldString;
String hurricaneSoldString;
String beignetSoldString;
double coffeePrice = 3.95;
double hurricanePrice = 8.95;
double beignetPrice = 2.95;
double salesTax = .09;
int coffeeSold;
int hurricaneSold;
int beignetSold;
double coffeeSales;
double hurricaneSales;
double beignetSales;
double subTotalSales;
double totalSalesTax;
double totalSales;
String enterTransaction;
String moreOrders;
// Prime the loop.
enterTransaction = JOptionPane.showInputDialog("Welcome to Crescent City Eats Are you ready to order? Enter Y or N");
// Validate input.
while(enterTransaction.compareTo("Y")!=0&&enterTransaction.compareTo("N")!=0)
{
enterTransaction = JOptionPane.showInputDialog("Invalid response. Please enter capital Y or N");
}
// Enter loop if they want to play.
while(enterTransaction.compareTo("Y") == 0)
{
// Get input
coffeeSoldString = JOptionPane.showInputDialog("Enter How Many Chickory Coffee Sold: ");
hurricaneSoldString = JOptionPane.showInputDialog("Enter How Many Hurricanes Sold: ");
beignetSoldString = JOptionPane.showInputDialog("Enter How Many Beignets Sold: ");
// Convert input to correct data type
coffeeSold = Integer.parseInt(coffeeSoldString);
hurricaneSold = Integer.parseInt(hurricaneSoldString);
beignetSold = Integer.parseInt(beignetSoldString);
coffeeSales = coffeeSold * coffeePrice;
hurricaneSales = hurricaneSold * hurricanePrice;
beignetSales = beignetSold * beignetPrice;
subTotalSales = coffeeSales + hurricaneSales + beignetSales;
totalSalesTax = salesTax * subTotalSales;
totalSales = subTotalSales + totalSalesTax;
System.out.println("\tFat Tuesday Eats\n");
System.out.println(coffeeSold +"\tChicory Coffee\t"+coffeeSales);
System.out.println(hurricaneSold +"\tHurricane\t"+hurricaneSales);
System.out.println(beignetSold +"\tBeignet\t\t"+beignetSales);
System.out.println("\tSubtotal\t"+subTotalSales);
System.out.println("\tSales Tax\t"+totalSalesTax);
System.out.println("\tTotal\t\t"+totalSales);
enterTransaction = JOptionPane.showInputDialog("Would you like to make another? Y or N");
while(enterTransaction.compareTo("Y")!=0&&enterTransaction.compareTo("N")!=0)
{
enterTransaction = JOptionPane.showInputDialog("Invalid response. Please enter capital Y or N");
}
if(enterTransaction.compareTo("Y")==0)
{
enterTransaction ="Y";
}
if(enterTransaction.compareTo("N") == 0)
{
System.out.println("Thanks for shopping.");
}
} // End of while loop.
System.exit(0);
} // End of main() method.
} // End of GuessNumber class.
I'm really not sure what he's going to ask us to do. If you have any guesses I would surely appreciate it.
I know we're going to have "if, if else, etc" and "do, do while, etc" that will be incorporated...I just dont completely know where. I know I'll need a counter to sum all of it up for daily total sales, but I dont know where to insert it
Forgive my lack of Java knowledge, it's the very first java class and balancing school and full-time work has been difficult.
Thanks in advance!

New Topic/Question
Reply
MultiQuote






|