i have to write a simple java program
write an application that determines the value of coins in a jar and prints the total in dollars and cents. Read integer values that represent the number of quarters, dimes, nickels and pennies

so i did it i don't know where to go from here help would be appreciated

public class coins {

public static void main(String[] args) {

double quarters;
double dimes;
double nickels;
double pennies;
double money;

Scanner scan = new Scanner(System.in);
System.out.println("Enter the number of quarters in the jar.");
quarters = scan.nextInt();
System.out.println("Enter the number of dimes in the jar");
dimes= scan.nextInt();
System.out.println("Enter the number of nickels in the jar");
nickels = scan.nextInt();
System.out.println("Enter the number of pennies in the jar");
pennies = scan.nextInt();
money = quarters*25 + dimes*10 + nickels*5 + pennies*1;
System.out.println("Your total change in dollars and cents is "+money);

}
}

the last 2 have to be in dollar like 81 dollars and 27 cents but i get dollar is and cents is 81.00 i dont no the code to split it,i dont understand floating what where do i put it ??? any one help me out

i have to write a simple java program
write an application that determines the value of coins in a jar and prints the total in dollars and cents. Read integer values that represent the number of quarters, dimes, nickels and pennies

so i did it i don't know where to go from here help would be appreciated

public class coins {

public static void main(String[] args) {

double quarters;
double dimes;
double nickels;
double pennies;
double money;

Scanner scan = new Scanner(System.in);
System.out.println("Enter the number of quarters in the jar.");
quarters = scan.nextInt();
System.out.println("Enter the number of dimes in the jar");
dimes= scan.nextInt();
System.out.println("Enter the number of nickels in the jar");
nickels = scan.nextInt();
System.out.println("Enter the number of pennies in the jar");
pennies = scan.nextInt();
money = quarters*25 + dimes*10 + nickels*5 + pennies*1;
System.out.println("Your total change in dollars and cents is "+money);

}
}

the last 2 have to be in dollar like 81 dollars and 27 cents but i get dollar is and cents is 81.00 i dont no the code to split it,i dont understand floating what where do i put it ??? any one help me out

Well, you can use DecimalFormat to format money after dividing by 100. quarters , dimes , nickels , pennies should be integers, not doubles.

quarters = scan.nextInt();

http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html

or you can make money an integer and have two variables, dollars and cents, and split money up into those components using the / and % operators. So if money = 2343, dollars would equal 23 and cents would equal 43. Then output a dollar sign, then dollars , then a decimal point, then cents . You'd have to pad cents with a 0 if it's less than ten cents.

commented: Nice reply Sir...Thanks +2

i solved this thx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.