Results 1 to 6 of 6
  1. #1
    l1r1m is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default need help to FIX this program

    /** TotalVariables computes the amount of change I have, based on the values
    * named by the four variables, quarters, dimes, nickels, and pennies. */
    public class TotalVariables
    { public static void main(String[] args)
    { int quarters = 9;
    int dimes = 2;
    int nickels = 0;
    int pennies = 6;
    System.out.println("For these quantities of coins:");
    System.out.print("Quarters = ");
    System.out.println(quarters);
    System.out.print("Dimes = ");
    System.out.println(dimes);
    System.out.print("Nickels = ");
    System.out.println(nickels);
    System.out.print("Pennies = ");
    System.out.println(pennies);
    System.out.println( (quarters * 25) + (dimes * 10)
    + (nickels * 5) + (pennies * 1) );
    }
    }


    and my problem is how to make the program ask the user to ENTER THE VALUES for quarters, dimes, nickles and pennies when it runs.
    I tried the "imput command" but i couldnt do it right i guess :(
    So, please help me.
    thanks

  2. #2
    l1r1m is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    and ...I am sorry if i didn't put this thread in the right place.

  3. #3
    l1r1m is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    oo god i put it in the job disscusion, i thought it was JAVA DISSCUSION

  4. #4
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    I belive you can do like this:
    Java Code:
    int coins;
    InputStream stream = new InputStream(System.in);
    do{
    coins = stream.nextInt();
    } while (coins == null);
    Some thing in that direction should work..

  5. #5
    unideal is offline Member
    Join Date
    Dec 2009
    Posts
    8
    Rep Power
    0

    Default

    My solution:


    Java Code:
    import java.util.Scanner;
    
    public class TotalVariables {
    
    	public static void main(String[] args) { 
    		
    		/* Scanner object for reading user input */
    		
    		Scanner scanner = new Scanner(System.in);
    		
    		/* Read the values for quarters, dimes, nickels and pennies */
    		
    		System.out.print("Give the quantity of Quarters: ");
    		int quarters = scanner.nextInt();
    		
    		System.out.print("Give the quantity of Dimes: ");
    		int dimes = scanner.nextInt();
    		
    		System.out.print("Give the quantity of Nickels: ");
    		int nickels = scanner.nextInt();
    		
    		System.out.print("Give the quantity of Pennies: ");
    		int pennies = scanner.nextInt();
    		
    		/* Print the quantities */
    		
    		System.out.println("For these quantities of coins:");
    		System.out.print("Quarters = ");
    		System.out.println(quarters);
    		
    		System.out.print("Dimes = ");
    		System.out.println(dimes);
    		
    		System.out.print("Nickels = ");
    		System.out.println(nickels);
    		
    		System.out.print("Pennies = ");
    		System.out.println(pennies);
    		
    		System.out.print("TOTAL: ");
    		System.out.println( (quarters * 25) + (dimes * 10) + (nickels * 5) + (pennies * 1) );
    		
    	}	
    }

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by l1r1m View Post
    oo god i put it in the job disscusion, i thought it was JAVA DISSCUSION
    This thread has been moved to the New to Java forum for better topic alignment.

Similar Threads

  1. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 07:53 PM
  2. Execute A program from a Program!
    By Moncleared in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2009, 05:17 PM
  3. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 09:24 AM
  4. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •