Results 1 to 2 of 2
Like Tree2Likes
  • 2 Post By sunde887

Thread: [URGENT] Due in 1.5 hrs. VERY easy java project question

  1. #1
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Default [URGENT] Due in 1.5 hrs. VERY easy java project question

    This is the assignment: Write an interactive program to calculate the change (quarters, dimes, nickels,
    pennies) from an amount entered. For example, if the user inputs 1.47, the program
    should display the following:
    1.47 is equivalent to the following:
    5 quarters
    2 dimes
    0 nickels
    2 pennies
    *** End of Program ***

    However, when I do this, let's say I enter 1.26, it tells me:
    Java Code:
    Enter the cash amount: 
    1.26
    1.26 is equal to the following:
    5.04 Quarters 
    
    1.26 is equal to the following:
    12.6 Dimes 
    
    1.26 is equal to the following:
    25.2 Nickels 
    
    1.26 is equal to the following:
    126.0 Pennies 
    
    ***End of Program***
    I want it to tell me 5 quarters, 0 dimes, 0 nickels, and one penny. Any idea how I could change it so that works?

    This is my code -
    Java Code:
    //************************************************************************
    // Name: TJ Class: CSC 120 Assignment: Program 1
    // 
    //Due Date: Septemeber 28th, 11:59 PM 
    // 
    // Purpose: To display number of
    // Quarters, Nickels, dimes, and pennies in a dollar amount. (Ex. $1.28)
    //************************************************************************
    package program1;
    
    import java.util.Scanner;
    
    public class CSC120Program1 {
    
    	
    	public static void main(String[] args) 
    	{
    		double cash;
    		double Q = 0.25, coins;
    		
    		Scanner scan = new Scanner (System.in);
    	
    		System.out.print("Enter the cash amount: \n");
    		cash = scan.nextDouble();
    		
    			coins = cash / Q;
    		
    		System.out.println(cash + " is equal to the following:\n" + coins + " Quarters " + "\n");
    		
    			Q = 0.10;
    		
    			coins = cash / Q;
    		
    		System.out.println(cash + " is equal to the following:\n" + coins + " Dimes " + "\n");
    		
    			Q = 0.05;
    		
    			coins = cash / Q;
    		
    		System.out.println(cash + " is equal to the following:\n" + coins + " Nickels " + "\n");
    		
    			Q = 0.01;
    		
    			coins = cash / Q;
    		
    		System.out.println(cash + " is equal to the following:\n" + coins + " Pennies " + "\n");
    		
    
    		System.out.println("***End of Program***");
    	}
    
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: [URGENT] Due in 1.5 hrs. VERY easy java project question

    Don't use [URGENT] in the title.
    DarrylBurke and Fubarable like this.

Similar Threads

  1. Project Question Urgent?
    By newtocs in forum New To Java
    Replies: 1
    Last Post: 10-09-2009, 02:55 PM
  2. general confused about java question (easy!)
    By sweetjava in forum New To Java
    Replies: 1
    Last Post: 08-09-2009, 02:03 AM
  3. New to Java and have an easy question
    By JBOY08 in forum New To Java
    Replies: 1
    Last Post: 11-19-2008, 07:40 PM
  4. Easy program...need help (urgent)
    By Zebra in forum New To Java
    Replies: 25
    Last Post: 05-30-2008, 08:51 AM

Posting Permissions

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