Question

ONLY ACCEPTING AS A TEXT FILE. Write a program (java) that determines the value of the...

ONLY ACCEPTING AS A TEXT FILE. Write a program (java) that determines the value of the 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.

Homework Answers

Answer #1

Code - Main,java , and read input for quarters, dimes,nickels. and pennies. from input.txt

import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException
{
//variabled declare to be used
int quarters, dimes, nickels, pennies;
int dollor;
//read value of quarters, dimes, nickels, pennies from file input.txt
Scanner scanner = new Scanner(new File("input.txt"));
//store the value read from file in input array
int [] input = new int [4];
int i = 0;
//reading values from file
while(scanner.hasNextInt())
{ //storing the value in input array
input[i++] = scanner.nextInt();
}
//initialize the variable to their corresponding value
quarters = input[0];
dimes = input[1];
nickels = input[2];
pennies = input[3];
//print out the value read from file and display
System.out.println("Number of quarters in the jar: "+quarters);
System.out.println("Number of dimes in the jar: "+dimes);
System.out.println("Number of nickels in the jar: "+nickels);
System.out.println("Number of pennies in the jar: "+pennies);
//calculate the value in cents
int cents = 25*quarters + dimes*10 + nickels*5 + pennies;
//convert it to dollor
dollor = cents/100;
cents = cents %100;
//print the last result
System.out.println("Total is " + dollor + " dollars and " + cents + " cents ");
}
}

input.txt -

Output -

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
program has to be written in X86 processor assy language. Write a program that find the...
program has to be written in X86 processor assy language. Write a program that find the minimum number of coins that can represent an amount of money under $1. The amount of money is a random number between 0 and 99 (cents). The randomRange procedure is used to get a random number. Review the sample code in lab4.asm and run it to see how randomRange works. Each time randomRange is called, it creates a random number between 0 and the...
Write a program that reads three integer values from the keyboard using the Scanner class representing,...
Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.
4) Create the following in a Java program. Create a Scanner Prompt the user to Receive...
4) Create the following in a Java program. Create a Scanner Prompt the user to Receive the amount and declare the variable double amount for scanner Declare variable integer remaining amount which is equal to (int) (amount*100) Find the number of one dollars bt declaring the integer variable which is equal to remaining amount divided by 100 Declare: remaining amount %=100 Find the number of quarters: Declare integer variable number of quarters equal to remaining amount divided by 25 Declare:...
USE PYTHON Please!!! 4.15 LAB: Exact change Write a program with total change amount as an...
USE PYTHON Please!!! 4.15 LAB: Exact change Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1...
Write a program that reads three integer values from the keyboard using the Scanner class representing,...
Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.
Write a program that input some number of cents (see less than 100), and output the...
Write a program that input some number of cents (see less than 100), and output the number of quarters, dimes, nickels and pennies needed to add up to that amount (thinking how a cashier needs to return you back some small changes).
Write a C program that prints 1 if there is an exact change using nickels (5...
Write a C program that prints 1 if there is an exact change using nickels (5 cents), dimes (10 cents), quarters (25 cents), loonies ($1), toonies ($2) and bills and 0 if there is none. For example, if the change is $7.25 it prints 1 because, the change would be 7 loonies($1), two dimes and a nickel.  
6.         Write a single statement that prompts the user to enter their age in years and places...
6.         Write a single statement that prompts the user to enter their age in years and places the integer value in a variable named age. 7.         Can a program place more than one statement on the same program line? 8.         Write a short code segment in Python that prompts the user to enter the number of quarters, dimes, nickels and pennies they have, compute the total value and print that value.
java program; Write a brief program that writes your name to a file in text format...
java program; Write a brief program that writes your name to a file in text format and then reads it back. Use the PrintWriter and Scanner classes.
1.      Create 100 text files automatically; in each file write a random number from 1 to 10....
1.      Create 100 text files automatically; in each file write a random number from 1 to 10. Use outputstreams (fileoutputstream, buffredwriter….) 2.      Read the content of the 100 files and combine them into a 1 single file. 3.      Write java code to do the following: a.      To write the following text into a text file EEEESAAA@23SDCFSAWERF%WASDFGHWERTRQW b.      Read the file using a java program c.      Find how many D’s in the file d.      Extract the text between the @ and the # 1. Create 100 text files...