Hey all I have a few lab assignments due this Friday and I am new to JAVA and programming in general. This specific assignment requires me to write a program that calculates the total sales after each football game. There are 4 types of tickets: box, sideline, premium, and general admission. After each game, data is stored in a file... then output the number of tickets sold and total sale amount. Format your output with 2 decimal places.
Okay I know there is a I/O section and wasnt sure where to post this. I need some insight on how to use file input and output as well if anyone can give me some ideas how to "clean" my program up a little. I feel like its a lot longer than it has to be but again I am a total noob and only have little knowledge of programming. Here is my program:
import javax.swing.JOptionPane; import java.text.DecimalFormat; public class ticketsSold { public static void main(String[] args) { String BoxSeat; String SideLine; String PremiumSeat; String GeneralSeat; double boxCost = 250.00; double sideCost = 100.00; double premiumCost = 50.00; double generalCost = 25.00; double box; double side; double premium; double general; String newDecimal; String newDecimal1; String newDecimal2; String newDecimal3; String newDecimal4; BoxSeat = JOptionPane.showInputDialog("Enter how many box tickets were sold: "); box = Double.parseDouble(BoxSeat); SideLine = JOptionPane.showInputDialog("Enter how many sideline tickets were sold: "); side = Double.parseDouble(SideLine); PremiumSeat = JOptionPane.showInputDialog("Enter how many premium tickets were sold: "); premium = Double.parseDouble(PremiumSeat); GeneralSeat = JOptionPane.showInputDialog("Enter how many general tickets were sold: "); general = Double.parseDouble(GeneralSeat); double totalBox = (box * boxCost); double totalSide = (side * sideCost); double totalPremium = (premium * premiumCost); double totalGeneral = (general * generalCost); double grandTotal = (totalBox + totalSide + totalPremium + totalGeneral); DecimalFormat formatter = new DecimalFormat("#0.00"); newDecimal = (formatter.format(grandTotal)); newDecimal1 = (formatter.format(totalBox)); newDecimal2 = (formatter.format(totalSide)); newDecimal3 = (formatter.format(totalPremium)); newDecimal4 = (formatter.format(totalGeneral)); JOptionPane.showMessageDialog(null, "The total number of $250.00 box seats sold this" + " week: " + box + " seats netting: $" + newDecimal1 + "\nThe total number of $100.00 sideline" + " seats sold this week: " + side + " tickets" + " netting: $" + newDecimal2 + "\nThe total number" + " of $50.00 premium seats sold this week: " + premium + " seats netting: $" + newDecimal3 + "\nThe total number of $25.00 general seats sold this" + " week: " + general + " seats netting: $" + newDecimal4 + "\nThe grand total of sales for the" + " MCC football stadium this week is: $" + newDecimal + "", "MCC Stadium Report", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } }