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: need Help to get this program running

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need Help to get this program running

    Question:
    Write a program that will calculate the cost of a ticket order and display the receipt for the customer on the screen. There are 2 ticket prices: adult, and senior citizen. Adult seats are $4.50 and senior citizen seats are $3.50. If more than 5 senior citizen tickets are purchased, the customer gets an extra 20% off the of the ticket order. If more than 10 regular seats are purchased, the customer gets an additional 10% off the cost of the order. A customer can only place an order for one type of ticket. Output the type of ticket purchased, the number of tickets purchased, the gross cost, the amount of the discount, and the final cost of the order.

    I am having errors with incaompatible varriables comparing float with doubles. Can someone please help me solve this program running.
    Thanks a lot

    public class lab3
    {
     
       static Library myLib;
     
       public static void main (String [] args)
      	{
     
             Library myLib          = new Library();                 //Instance the Library class
             int ticketNum;                                          //Number of Tickets
    		 char adult;                                             //Ticket Type
    		 char senior;
    		 char ticketType;
    		 final double ADULT_SEAT = 4.50;
    		 final double SENIOR_SEAT = 3.50;
    		 final double ADULT_DISCOUNT = 0.10;
    		 final double SENIOR_DISCOUNT = 0.20;
    		 int age;
    		 float totalCost;                                        //total cost of the tickets
    		 float grossCost;                                        //gross cost without discount
    		 float discount;									     //amount of discount
    		 int discountRate;
    		 discountRate = 0;                                   //Initializing discount rate to 0
     
             /********************   Start main method  *****************/
     
             //Prompt for Ticket Type
             adult = 0;
             senior = 0;
             System.out.println("\n\n");
             System.out.print("Ticket Types, adult or senior   :    ");
             ticketType = Keyboard.readChar();
             if (ticketType == adult || ticketType == senior)
             {
            	System.out.println("Number of Tickets : ");
             	ticketNum = Keyboard.readInt();
    		 }
    		 else{
    		 	System.out.println("You have entered invalid ticket type. Please try again");
     
    		 	//clear the screen
                myLib.clrscr();
     
    		}
    		System.out.println("\n\n");
    		//Calc
    		if(ticketType == adult && ticketNum >=10)
    		{
    			totalCost = grossCost - discount;
    			grossCost = ADULT_SEAT * ticketNum;
    			discount = grossCost * ADULT_DISCOUNT;
    		}
    		else
    			totalCost = ADULT_SEAT * ticketNum;
    		if (ticketType == senior && ticketNum >=5)
    		{
    			totalCost = grossCost - discount;
    			grossCost = SENIOR_SEAT * ticketNum;
    			discount = grossCost * SENIOR_DISCOUNT;
    		}
    }
    }//end


  2. #2
    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: need Help to get this program running

    I am having errors
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need Help to get this program running

    I tried running it now, but it does not really do any calculation or displays any error message if i enter any char other than adult or senior,
    So basically, it is not running anything that it was supposed to be, or is not calculating any calculations.

    --- Update ---

    This is what I have for my codes


    public class lab3
    {
     
       static Library myLib;
     
     
     
       public static void main (String [] args)
      	{
     
             Library myLib          = new Library();                 //Instance the Library class
             int ticketNum;                                          //Number of Tickets
    		 char adult;                                             //Ticket Type
    		 char senior;
    		 char ticketType;
    		 final float ADULT_SEAT = 4.50f;
    		 final float SENIOR_SEAT = 3.50f;
    		 final float ADULT_DISCOUNT = 0.10f;
    		 final float SENIOR_DISCOUNT = 0.20f;
    		 float totalCost;                                        //total cost of the tickets
    		 float grossCost;                                        //gross cost without discount
    		 float discount;									     //amount of discount
     
             /********************   Start main method  *****************/
     
             //Prompt for Ticket Type
    		 ticketType = 0;
    		 adult      = 0;
    		 senior     = 0;
    		 ticketNum  = 0;
             System.out.println("\n\n");
             System.out.print("Ticket Types, adult or senior   :    ");
             if (ticketType == adult || ticketType == senior)
             {
    			ticketType = Keyboard.readChar();
            	System.out.println("Number of Tickets : ");
             	ticketNum = Keyboard.readInt();
    		 }
    		 else{
    		 	System.out.println("You have entered invalid ticket type. Please try again");
     
    		 	//clear the screen
                myLib.clrscr();
     
    		}
    		System.out.println("\n\n");
     
    		//Calculating Total Cost of Tickets
    		totalCost  = 0;
    		grossCost  = 0;
    		discount   = 0;
     
    		if(ticketType == adult && ticketNum >=10)
    		{
    			totalCost = grossCost - discount;
    			grossCost = ADULT_SEAT * ticketNum;
    			discount = grossCost * ADULT_DISCOUNT;
    		}
    		else
    			totalCost = ADULT_SEAT * ticketNum;
     
    		if (ticketType == senior && ticketNum >=5)
    		{
    			totalCost = grossCost - discount;
    			grossCost = SENIOR_SEAT * ticketNum;
    			discount = grossCost * SENIOR_DISCOUNT;
    		}
     
    		//Output
    		         System.out.println("\n\n\n");
    				 System.out.println("\t\t\t   Scheemaker Stadium Ticket Receipt ");
    				 System.out.println("\t\t\t   ---------------------------------- \n");
    				 System.out.println("\t\tTicket Type          :" +ticketType);
    				 System.out.println("\t\tNumber of Tickets    :" +ticketNum);
    				 System.out.println("\t\tTicket Cost          :" +grossCost);
    				 System.out.println("\t\tDiscount Amount      :" +discount);
    				 System.out.println("\t\tFinal Cost           :" +totalCost);
     
    		 	     System.out.println("\n\n\n\n\n\n\n");
    		 	     //pause the screen - this statement is not needed in this program
             //myLib.pause();
    }
    }//end

  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: need Help to get this program running

    Can you explain what problems you are having?
    Copy the contents of the console window and paste it here and add some comments describing the problems.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need Help to get this program running

    When the program prompts me to enter senior or adult, i entered "senior" without quote. And this is what it produce as an output


    Error reading int data, MIN_VALUE value returned.







    Scheemaker Stadium Ticke
    ------------------------

    Ticket Type :s
    Number of Tickets :-2147483648
    Ticket Cost :0.0
    Discount Amount :0.0
    Final Cost :-9.6636764E9
    Press any key to continue . . .

    When entered "adult", this is what it outputs

    Ticket Types, adult or senior : adult
    Number of Tickets :
    Error reading int data, MIN_VALUE value returned.







    Scheemaker Stadium Ticket Receipt
    ----------------------------------

    Ticket Type :a
    Number of Tickets :-2147483648
    Ticket Cost :0.0
    Discount Amount :0.0
    Final Cost :-9.6636764E9
    Press any key to continue . . .
    And it does not even gimme an option to enter number of tickets
    When entered invalid ticket type, this is what it output

    Ticket Types, adult or senior : saddasadad
    Number of Tickets :
    Error reading int data, MIN_VALUE value returned.







    Scheemaker Stadium Ticket Receipt
    ----------------------------------

    Ticket Type :s
    Number of Tickets :-2147483648
    Ticket Cost :0.0
    Discount Amount :0.0
    Final Cost :-9.6636764E9








    Press any key to continue . . .


    I don't know why its not running

  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: need Help to get this program running

    Because you are using non standard java classes: Keyboard and Library, it is not possible for me to test the code the same way you are. When I hard code some values in the code:
    			ticketType = 's'; //>>>>>>>>>Keyboard.readChar(); 
             	ticketNum = 3; //>>>>>>>>>Keyboard.readInt();
    I get this output:
     
    			   Scheemaker Stadium Ticket Receipt 
    			   ---------------------------------- 
     
    		Ticket Type          :s
    		Number of Tickets    :3
    		Ticket Cost          :0.0
    		Discount Amount      :0.0
    		Final Cost           :13.5
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Sep 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Help Getting codes In

    Lab: There are 2 ticket prices: adult, and senior citizen. Adult seats are $4.50 and senior citizen seats are $3.50. If more than 5 senior citizen tickets are purchased, the customer gets an extra 20% off the of the ticket order. If more than 10 regular seats are purchased, the customer gets an additional 10% off the cost of the order. A customer can only place an order for one type of ticket. Output the type of ticket purchased, the number of tickets purchased, the gross cost, the amount of the discount, and the final cost of the order.

    Pseudo-code:

    INPUTS
    Ticket Type Char
    Number of Tickets Integer

    CONSTANTS
    adult = 'a'
    senior= 's'
    adults seat = $4.50 per ticket
    senior seat = $3.50 per ticket

    CALCULATION AND PROCESS
    Final Cost = Gross Cost - Discount
    Gross Cost = adult/senior seat * number of tickets
    If senior tickets are purchased 5 or more then they will get 20% discount
    If adults tickets are purchased 10 or more then they will receive 10% discount

    Discount = gross cost * discount rate
    Validate if the ticket type is valid ticket type: senior or adult.
    if it is invalid display a error message and prompt them to try again

    OUTPUT
    Receipt:
    Ticket Type :
    Number of Ticket:
    Gross Cost:
    Discount: If applicable
    Final Cot




    I really need help on this please. Any help is highly appreciated. Thanks a lot.

  8. #8
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: Need Help Getting codes In

    What have you got down so far?

Similar Threads

  1. Running my Java first program
    By gauthamtin15 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 5th, 2014, 07:02 AM
  2. Replies: 21
    Last Post: June 12th, 2013, 11:33 AM
  3. Entering and running a Program
    By Bijaysadhok in forum Java Theory & Questions
    Replies: 1
    Last Post: February 23rd, 2012, 07:15 AM
  4. Running into a problem with my program.
    By letsgetlifted in forum What's Wrong With My Code?
    Replies: 9
    Last Post: December 9th, 2011, 07:09 PM
  5. NullPointerException when running program...
    By RiskyShenanigan in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 12th, 2011, 04:30 PM