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

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




file input and compiling problems for ticket sales program

 
Reply to this topicStart new topic

file input and compiling problems for ticket sales program

soccerplayer
18 Sep, 2007 - 01:37 PM
Post #1

New D.I.C Head
*

Joined: 18 Sep, 2007
Posts: 5


My Contributions
Hi, I am having a tremendous amount of trouble in my computer science class! We are doing java and I just feel like I am so behind and I can't understand what my teacher is talking about. Anyway, we are assigned a program assignment that I have been working on for days and I cannot get to work. The program is due tomorrow!

I also noticed someone else had already posted this same program problem but the replies didn't help my specific problems

The assignment is :

The manage of a football team 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:

ticket price numberOfTicketsSold

sample data

250 5750
100 28000
50 35750
25 18750

The first line indicates that the box ticket price is $250 and that 5,570 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 sold and overall sales amount.

I have constantly been looking at examples in my book but I dont understand how to do this inputing a file. My file with the sample data in it is called ticketSales.dat
I asked the user to input data but maybe im not supposed to do that because I'm supposed to use the file? But I dont know how?

This is my code:

CODE

import javax.swing.JOptionPane;
import java.io.*;

public class TicketSales
{
    public static void main(String[] args)
    {
        String inputStr;
        String outputStr;
        int noOfTicketsSoldBox;
        int noOfTicketsSoldSideline;
        int noOfTicketsSoldPremium;
        int noOfTicketsSoldGeneral;
        double totalSaleAmountBox;
        double totalSaleAmountSideline;
        double totalSaleAmountPremium;
        double totalSaleAmountGeneral;
        int totalTicketsSold;
        double totalSalesAmount;

        Scanner input =
          new Scanner("ticketSales.dat");

        inputStr = JOptionPane. showInputDialog
            ("Please enter the total number of tickets sold for Box Seat Admission");    
        noOfTicketsSoldBox= Integer.parseInt(inputStr);

        inputStr = JOptionPane. showInputDialog
            ("Please enter the total number of tickets sold for Sideline Seat Admission");    
        noOfTicketsSoldSideline = Integer.parseInt(inputStr);

        inputStr = JOptionPane. showInputDialog
            ("Please enter the total number of tickets sold for Premium Seat Admission") ;      
        noOfTicketsSoldPremium = Integer.parseInt(inputStr);

        inputStr = JOptionPane. showInputDialog
            ("Please enter the total number of tickets sold for General Admission");      
        noOfTicketsSoldGeneral = Integer.parseInt(inputStr);
        
        totalSaleAmountBox = noOfTicketsSoldBox  * 250;
        totalSaleAmountSideline = noOfTicketsSoldSideline * 100;
        totalSaleAmountPremium = noOfTicketsSoldPremium * 50;
        totalSaleAmountGeneral = noOf
icketsSoldGeneral * 25;
        totalTicketsSold = noOfTicketsSoldBox + noOfTicketsSoldSideline + noOfTicketsSoldPremium + noOfTicketsSoldGeneral;
        totalSalesAmount = totalSaleAmountBox + totalSaleAmountSideline + totalSaleAmountPremium + totalSaleAmountGeneral;
        


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

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

            + "Number Of Total Tickets Sold: "
            + (totalTicketsSold) + "\n"
            + "Total Sales Amount: $"
            + String.format("%.2f", totalSalesAmount) + "\n";
        
        JOptionPane.showMessageDialog(null, outputStr,
            "Football Ticket Sales",
            JOptionPane.INFORMATION_MESSAGE);
        
        System.exit(0);
    }
}


When I have tried to put it in my command prompt the error reads :
TicketSales.java:72:not a statement
+ String.format("%.2f", totalSalesAmount) + "\n";
^

1 error


Even though theres only one error I think I'm not doing the program as assigned!
I am so confused so if anyone could help me with my problem it would be extremely appreciated!!!

Thanks! smile.gif




User is offlineProfile CardPM
+Quote Post

Jayman
RE: File Input And Compiling Problems For Ticket Sales Program
18 Sep, 2007 - 02:27 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,306



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
You need to remove the semi-colon found in the following screen shot. Once you remove that, you will see the rest of the underlying errors that are mostly related to typos in your variable names. You also forgot to import the Scanner class.


Attached thumbnail(s)
Attached Image
User is offlineProfile CardPM
+Quote Post

soccerplayer
RE: File Input And Compiling Problems For Ticket Sales Program
18 Sep, 2007 - 08:16 PM
Post #3

New D.I.C Head
*

Joined: 18 Sep, 2007
Posts: 5


My Contributions
How do i import the scanner class? I think that might be what i cant get!

Thanks!
User is offlineProfile CardPM
+Quote Post

soccerplayer
RE: File Input And Compiling Problems For Ticket Sales Program
19 Sep, 2007 - 09:06 AM
Post #4

New D.I.C Head
*

Joined: 18 Sep, 2007
Posts: 5


My Contributions
Now that i fixed that there are 14 errors! They are all either cannot find symbol or illegal start to type. And i really cant understand how to import the scanner class or get the data from the file. I dont know how I'm gonna figure this out !


please help!!

User is offlineProfile CardPM
+Quote Post

soccerplayer
RE: File Input And Compiling Problems For Ticket Sales Program
19 Sep, 2007 - 09:12 AM
Post #5

New D.I.C Head
*

Joined: 18 Sep, 2007
Posts: 5


My Contributions
Actually nevermind the 14 errors, I fixed the variable problems and now i only have 2. They both have to do with the Scanner import, so if anyone just knows how to import the scanner and input data from my file?

User is offlineProfile CardPM
+Quote Post

Jayman
RE: File Input And Compiling Problems For Ticket Sales Program
19 Sep, 2007 - 09:12 AM
Post #6

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,306



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
CODE
import java.util.Scanner
, the rest of the error are typos. Check the name of the variables that you declared against the names you use later in code, you will see the mistakes.
User is offlineProfile CardPM
+Quote Post

soccerplayer
RE: File Input And Compiling Problems For Ticket Sales Program
19 Sep, 2007 - 09:19 AM
Post #7

New D.I.C Head
*

Joined: 18 Sep, 2007
Posts: 5


My Contributions
Thank you so much. I must have written the program wrong because it has me input numbers instead of reading the data from ticketSales.dat however, none of the excercises in my textbook are programs read from a file so i have no idea how to go about doing that. I wish i understood this
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:53PM

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