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

Thread: Need Help Ran into problem

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Help Ran into problem

    // I seem to be having a problem when I run the program it doesnt come up line for line, I get one line then two lines in a row. I want to know how to make it so I input the test data request after request.


    import java.util.Scanner;
    public class M_C_LotteryWinnings
    {


    public static void main(String[] args)

    {
    System.out.println ("Welcome to Michael's pooled Lottery Winnings Calculater. \n");

    Scanner keyboard = new Scanner( System.in );

    System.out.println ( "Enter The Lottery Name:" );
    String name = keyboard.next();

    System.out.println ( "Enter the number of people in your lottery pool:" );
    String people = keyboard.next();

    System.out.println ( "Enter the total number of tickets purchased:" );
    int Tickets = keyboard.nextInt();

    if( Tickets % 100 != 0 )
    System.out.println( "Number of tickets must be a multiple of People in pool." );
    System.out.println ( "Enter the total number of tickets purchased:" );

    System.out.println ( "Enter the combined winnings on all tickets:" );
    int winnings = keyboard.nextInt();

    System.out.println ( "Enter the per-ticket Purchase Price:" );
    double price = keyboard.nextDouble();

    System.out.println ( "Enter the percentage of winnings that will be donated to charity:" );
    int donation = keyboard.nextInt();

    System.out.println ( "TRUE/FALSE: Allocations to be rounded down to the nearest multiple of $100:" );
    String rounded = keyboard.next();

    System.out.println ( "TRUE/False: Purchaser of richest winning ticket receives a double share:" );
    String richest = keyboard.next();

    {
    if( richest == "TRUE" )
    System.out.println ( " Richest Winning Ticket share: " + winnings / 4 *2 );
    }

    System.out.println( "Here are the allocations for your winnings in the Super Jackpot Lottery...\n " );

    System.out.println ( "Total Winnings: " + winnings );
    System.out.println ( "Number of shares: " + Tickets );

    {
    if( rounded == "True" )
    System.out.println ( "Winnings per share: " + (winnings / 4) *100 / 100 );
    System.out.println ( " Unallocated Winnings: $ " + ( winnings - donation - ( winnings / Tickets * Tickets ) * 100 / 100 ) );
    System.out.println ( " Percent ROI after donation: " + 100 * ( winnings - price ) / price * 100 / 100 );
    if( rounded == "False" )
    System.out.println ( "Winnings per Share: " + winnings / 4 );
    System.out.println ( " Percent ROI after donation: " + 100 * ( winnings - price ) / price );
    System.out.println ( " Unallocated Winnings: $ " + ( winnings - donation - ( winnings / Tickets * Tickets ) ));
    }

    }
    // end main
    }
    // end class


  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 Ran into problem

    Can you copy the contents of the console window from when you execute the code and paste it here?

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

    One problem I see is the use of == to compare two String objects. You need to use the equals() method when comparing Strings.

    Also if you want to allow different spellings of words by ignoring the case, the String class has a method to do that.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need Help Ran into problem

    [QUOTE=Curran171;126410]// I seem to be having a problem when I run the program it doesnt come up line for line, I get one line then two lines in a row. I want to know how to make it so I input the test data request after request.

    import java.util.Scanner;
    public class M_C_LotteryWinnings
    {
     
     
    	public static void main(String[] args)
     
    	    {
    		System.out.println ("Welcome to Michael's pooled Lottery Winnings Calculater. \n");
     
    		Scanner keyboard = new Scanner( System.in );
     
    		System.out.println ( "Enter The Lottery Name:" );
    		String name = keyboard.next();
     
    		System.out.println ( "Enter the number of people in your lottery pool:" );
    		String people = keyboard.next(); 
     
    		System.out.println ( "Enter the total number of tickets purchased:" );
    		int Tickets = keyboard.nextInt();
     
    		if( Tickets % 100 != 0 )
    				System.out.println( "Number of tickets must be a multiple of People in pool." );
    			    System.out.println ( "Enter the total number of tickets purchased:" );
     
    		System.out.println ( "Enter the combined winnings on all tickets:" );
    		int winnings = keyboard.nextInt();
     
    		System.out.println ( "Enter the per-ticket Purchase Price:" );
    		double price = keyboard.nextDouble();
     
    		System.out.println ( "Enter the percentage of winnings that will be donated to charity:" );
    		int donation = keyboard.nextInt();
     
    		System.out.println ( "TRUE/FALSE: Allocations to be rounded down to the nearest multiple of $100:" );
    		String rounded = keyboard.next();
     
    		System.out.println ( "TRUE/False: Purchaser of richest winning ticket receives a double share:" );
    		String richest = keyboard.next();
     
    		{
    			if( richest == "TRUE" )
    				System.out.println ( " Richest Winning Ticket share: " + winnings / 4 *2 );
    		}
     
    		System.out.println( "Here are the allocations for your winnings in the Super Jackpot Lottery...\n " );
     
    		System.out.println ( "Total Winnings: " + winnings );
    		System.out.println ( "Number of shares: " +  Tickets );
     
    		{
    		if( rounded == "True" )
    			System.out.println ( "Winnings per share: " + (winnings / 4) *100 / 100 );
    		    System.out.println ( " Unallocated Winnings: $ " + ( winnings - donation -  ( winnings / Tickets * Tickets ) * 100 / 100 ) );
    		    System.out.println ( " Percent ROI after donation: " + 100 * ( winnings - price ) / price * 100 / 100 );
    		if( rounded == "False" )
    			System.out.println ( "Winnings per Share: " + winnings / 4 );
    		    System.out.println ( " Percent ROI after donation: " + 100 * ( winnings - price ) / price  );
    		    System.out.println ( " Unallocated Winnings: $ " + ( winnings - donation - ( winnings / Tickets * Tickets ) ));
    		}
     
    	}	
         // end main
    	}
    // end class
    Last edited by Norm; October 16th, 2013 at 06:33 PM. Reason: removed ending /quote tag

  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 Ran into problem

    Can you copy the contents of the console window from when you execute the code and paste it here that shows what you are talking about.

    I see you haven't changed the == to equals() yet.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: January 5th, 2012, 01:44 AM
  2. Program compiled/ran as required - FAILED project WHY??????????
    By MISSAJ in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 23rd, 2010, 03:35 PM
  3. Midterm Java program copiled/ran but I still failed
    By MISSAJ in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 22nd, 2010, 09:08 AM
  4. [SOLVED] [Problem] imports javax.swing problem
    By Brollie in forum AWT / Java Swing
    Replies: 8
    Last Post: July 5th, 2009, 07:59 AM