Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: I had to write a code for a total ticket sales with filling int the information given in the book but my code doesn't run for some reason

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I had to write a code for a total ticket sales with filling int the information given in the book but my code doesn't run for some reason

    ticketprice numberOfTicketsSold
    250 5750
    100 28000
    50 35750
    25 18750



    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Scanner;
    import java.text.NumberFormat;
     
    class TotalTicketSales {
    	public static void main(String [] args) throws IOException{
    		int ticketPrice, ticketsSold, ticketTotal;
    		double totalSale;
     
    		Scanner inFile = new Scanner(new FileReader("tickets.dat"));
     
    		ticketPrice = inFile.nextInt(250);
    		ticketsSold = inFile.nextInt(5750);
    		ticketTotal = ticketsSold;
    		totalSale = ticketPrice * ticketsSold;
     
    		ticketPrice = inFile.nextInt(100);
    		ticketsSold = inFile.nextInt(28000);
    		ticketTotal += ticketsSold;
    		totalSale += ticketPrice * ticketsSold;
     
    		ticketPrice = inFile.nextInt(50);
    		ticketsSold = inFile.nextInt(35750);
    		ticketTotal += ticketsSold;
    		totalSale += ticketPrice * ticketsSold;
     
    		ticketPrice = inFile.nextInt(25);
    		ticketsSold = inFile.nextInt(18750);
    		ticketTotal += ticketsSold;
    		totalSale += ticketPrice * ticketsSold;
     
    		NumberFormat nf = NumberFormat.getCurrencyInstance();
     
    		System.out.println("Total Sales " + nf.format(totalSale));
    		System.out.println("Total Tickets Sold " + ticketTotal);
     
    		inFile.close();
    	}
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: I had to write a code for a total ticket sales with filling int the information given in the book but my code doesn't run for some reason


  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I had to write a code for a total ticket sales with filling int the information given in the book but my code doesn't run for some reason

    Yes my question is why does my code not give me any output? It is suppose to output total sales amount and total amount of tickets sold.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I had to write a code for a total ticket sales with filling int the information given in the book but my code doesn't run for some reason

    my code not give me any output?
    Does the code compile without any errors? It shouldn't execute if there are compiler errors.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I had to write a code for a total ticket sales with filling int the information given in the book but my code doesn't run for some reason

    it says it cant locate my ticket.dat but its their so I need a way to let it run itself off the info i provided instead of the dat. Not exactly sure what i'd have to change now. Any advice?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I had to write a code for a total ticket sales with filling int the information given in the book but my code doesn't run for some reason

    it says it cant locate my ticket.dat
    Put the tickets.dat file in the same folder with the TotalTicketSales.class file.
    When you execute the java command in that folder, the program should find the .dat file.

    If you are using an IDE, read the doc for the IDE to see how to use it.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I had to write a code for a total ticket sales with filling int the information given in the book but my code doesn't run for some reason

    If I want to run the code without having to use a dat file with the information I already have within the code how should I alter it to do so? I believe my code is to be used by itself. I don't think they want me use anything outside to the code to produce the desired output. So to reiterate how would i have to alter my code to produce the output without the need of anything outside it simple input output within the code with the information I provided? Again thank you for helping me.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I had to write a code for a total ticket sales with filling int the information given in the book but my code doesn't run for some reason

    how would i have to alter my code to produce the output without the need of anything outside it
    Put the data in an array and use a loop to go through the contents of the array.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. java code to create ticket
    By prabhat11 in forum Algorithms & Recursion
    Replies: 8
    Last Post: April 19th, 2013, 12:04 PM
  2. Replies: 1
    Last Post: November 2nd, 2012, 04:16 PM
  3. How can I write a class or something so I can run and test the following code?
    By michael305rodri in forum Java Theory & Questions
    Replies: 3
    Last Post: October 18th, 2012, 10:46 PM
  4. Code compiles fine but doesn't run Properly
    By nadirkhan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 9th, 2011, 12:46 PM
  5. Replies: 6
    Last Post: July 21st, 2011, 07:45 AM