Welcome to Dream.In.Code
Become a Java Expert!

Join 149,609 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,868 people online right now. Registration is fast and FREE... Join Now!




ticket sales

 
Reply to this topicStart new topic

ticket sales, java program

youngbuck03
17 Sep, 2007 - 02:11 PM
Post #1

New D.I.C Head
*

Joined: 10 Sep, 2007
Posts: 2


My Contributions
ok so i have got this project due but i am not sure if i imported or even used the right form. I used the import javax.swing.JOptionPane; but im am not sure if i should have used the improt java.io and import java.util method... Im so confused on which one i am to use or if it even matters here are the instructions i was given


This lab is designed to give the student practice in the design and implementation of a program that uses Objects and file input.

Problem Description: The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets -- box, sideline, premium and general admission. After each game, the data is stored in a file in the following form:

ticketPrice numberOfTicketsSold
...

Sample data are shown below:
250 5570
100 28000
50 35750
25 18750

The first line indicates that the box ticket price is $250 and that 5,750 tickets were sold at that price.
Output a table that shows the number of tickets sold and the sales amount for each ticket type followed by a total line showing the overall number of tickets shold and overall sales amount. Sample output follows

so according to these directions what method should i have used?

and here is my program


CODE

import javax.swing.JOptionPane;

public class TicketSale
{
   public static void main(String[] args)
   {
    String inputStr;
    String outputStr;
    int noOfBoxTicketsSold;
        int noOfSidelineTicketsSold;
        int noOfPremiumTicketsSold;
        int noOfGeneralAdmissionTicketsSold;
        double totalBoxSales;
        double totalSidelineSales;
        double totalPremiumSales;
        double totalGeneralAdmissionSales;

    totalBoxSales = noOfBoxTicketsSold  * 250;
    totalSidelineSales = noOfSidelineTicketsSold * 100
    totalPremiumSales = noOfPremiumTicketsSold * 50;
        totalGeneralAdmissionSales = noOfGeneralAdmissionTicketsSold * 25;
    
    inputStr = JOptionPane. showInputDialog
            ("Enter the total number of tickets sold for Box Seats")    
            noOfBoxTicketsSold= Integer.parseInt(inputStr);
    
    inputStr = JOptionPane. showInputDialog
        ("Enter the total number of tickets sold for Sideline Seats")
        noOfSidelineTicketsSold = Interger.parseInt(inputStr);

        inputStr = JOptionPane. showInputDialog
        ("Enter the total number of tickets sold for Premium Seating")
        noOfPremiumSeatsSold= Integer.parseInt(inputStr);

    inputStr = JOptionPane. showInputDialog
        ("Enter the total number of tickets sold for General Admission Seating")
        noOfPremiumSeatsSold= Integer.parseInt(inputStr);

     outputStr =  "Number Of Box Tickets Sold: "
            + (noOfBoxTicketsSold) + "\n"
            + Box Total: $"
        + String.format("%.2f", totalBoxSales) + " \n"
        
            + "Number Of Sideline Tickets Sold: "
            + (noOfSidelineTicketsSold) + "\n"
            + Sideline Total: $"
            + String.format("%.2f", totalSidelineSales) + "\n"

            + "Number Of Premium Tickets Sold: "
            + (noOfPremiumTicketsSold) + "\n"
            + Premium Total: $"
            + String.format("%.2f", totalPremiumSales) + "\n"
            
            + "Number Of General Tickets Sold: "
            + (noOfGeneralTicketsSold + "\n"
            + General Total: $"
            + String.format("%.2f", totalGeneralAdmissionSales) + "\n"

    JOptionPane.showMessageDialog(null, outputStr,
                        "Total Ticket Sales Data",
                        JOptionPane.INFORMATION_MESSAGE);
     System.exit(0);                                      
   }
}

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Ticket Sales
17 Sep, 2007 - 03:20 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Well right in the assignment there it mentions using a file. That right there is going to tell you that you will need java.io since io stands for input/output and that is to and from file. So you would need that. Since you are using a JOptionPane, you were right to include that package. You wouldn't include the java.util package unless you were dealing with collections, times and dates or misc utilities like a string tokenizer or a random number generator.

But your assignment doesn't read from the file. Did you mean for it to be that way? It seems the assignment wanted you to read the values in from the file instead of asking the user directly.

One last thing, be careful with your data conversions there. You declared some doubles and then multiplied them by integers. This will work but you should to make sure that your data types match so you don't either lose data (due to truncation) or have data type mismatch problems later.

Hope that has helped you out. smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:11AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month