6 Replies - 1962 Views - Last Post: 19 September 2007 - 10:19 AM Rate Topic: -----

#1 soccerplayer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-September 07

file input and compiling problems for ticket sales program

Posted 18 September 2007 - 02:37 PM

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:

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! :)

Is This A Good Question/Topic? 0
  • +

Replies To: file input and compiling problems for ticket sales program

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: file input and compiling problems for ticket sales program

Posted 18 September 2007 - 03:27 PM

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 image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#3 soccerplayer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-September 07

Re: file input and compiling problems for ticket sales program

Posted 18 September 2007 - 09:16 PM

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

Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 soccerplayer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-September 07

Re: file input and compiling problems for ticket sales program

Posted 19 September 2007 - 10:06 AM

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!!
Was This Post Helpful? 0
  • +
  • -

#5 soccerplayer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-September 07

Re: file input and compiling problems for ticket sales program

Posted 19 September 2007 - 10:12 AM

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?
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: file input and compiling problems for ticket sales program

Posted 19 September 2007 - 10:12 AM

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.
Was This Post Helpful? 0
  • +
  • -

#7 soccerplayer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-September 07

Re: file input and compiling problems for ticket sales program

Posted 19 September 2007 - 10:19 AM

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1