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 6 of 6

Thread: Java Programming help please

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Programming help please

    i am writing a program that would be used for ticket sales and their are 100 tickets and a person can only buy 4 at a time. i need my program to not go negative at the end and also i need to stop the user from entering a negative number here is the code please help!



    import java.util.Scanner;

    public class ticketmaster {

    public static void main(String[] args) {


    // Variable decoration uses strings , doubles and final doubles.

    Scanner in = new Scanner(System.in);

    int balanceTicket = 100;

    int desiredTicketAmount = 0;

    int buyers = 0;







    while (balanceTicket > 0)

    {

    System.out.println("please enter the number of tickets wanted");

    desiredTicketAmount = in.nextInt();


    if ( desiredTicketAmount > 4 )

    {
    System.out.println( "please enter a number less than 4 ");

    System.out.println();

    }

    else if ( desiredTicketAmount <= 4 )

    {

    buyers++;
    balanceTicket = balanceTicket - desiredTicketAmount;





    System.out.println (" the number of tickes left are : " + balanceTicket);

    System.out.println();



    }

    }





    System.out.println (" the number of customers: " + buyers );

    System.out.println();



    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,376
    Thanks
    49
    Thanked 2,208 Times in 2,181 Posts

    Default Re: Java Programming help please

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    i need my program to not go negative
    Use an if statement to test if the value will go negative BEFORE changing the value.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Java Programming help please

    what do u mean by that
    at the end of the program some times their will be two tickets left and if the user puts in the number 4 the program will go negitive and i need that to stop also i need to stop the user from entering a negative number

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,376
    Thanks
    49
    Thanked 2,208 Times in 2,181 Posts

    Default Re: Java Programming help please

    From your data:
    if(4 > 2) don't do it
    else do it

    If (user's number < 0) tell the user its wrong and ask for another number
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Programming help please

    where at in the code is the probelm and what do i need to add to fix it???

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,376
    Thanks
    49
    Thanked 2,208 Times in 2,181 Posts

    Default Re: Java Programming help please

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    where at in the code is the probelm
    Can you be more descriptive of "the problem"? You have been talking about 2 different problems.
    Which one are you currently working on?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java Programming (Object Oriented Programming) Assignment
    By azmilPhenom in forum Object Oriented Programming
    Replies: 3
    Last Post: December 21st, 2013, 06:26 AM
  2. Polymorphism Java Programming HELPP P.S. I am a beginner in Java Programming
    By judemartin99 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 20th, 2013, 02:21 PM
  3. Linked Lists Java Programming HELPP P.S. I am a beginner in Java Programming
    By judemartin99 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 20th, 2013, 02:19 PM
  4. Replies: 1
    Last Post: January 6th, 2013, 05:32 AM
  5. android programming vs game programming using java
    By vgoel38 in forum Android Development
    Replies: 4
    Last Post: September 8th, 2012, 05:48 PM