Question: Create a class named CookieJar and implement the following method in it. public static void cashingIn(File input, File output) This method receives an input file

Create a class named CookieJar and implement the following method in it. public static void cashingIn(File input, File output)

This method receives an input file with your count of coins given as pairs of integer and type of coin, e.g., 1 penny, 42 quarters, 9 nickels. The method reads number/coin- type pairs from the input file and write the total dollar amount to the output file. For example, given the input file 2 quarters 4 dimes 1 penny 3 nickels 3 pennies, the method prints You have $1.09 in the jar to the output file. The dollar amount should be formatted in 2 decimal places and with commas (when appropriate). In cases when the total amount in the jar is zero the method writes

Code:

 You have no money in the jar 

to the output file. The input file may contain coin pairs in one line or across different lines, may contain several counts of the same type of coin at different times, and may list the type of coin in plural or singular form, e.g., pennies for many 1 cent coins or penny for one coin. Pennies are worth 1 cent each, nickels are worth 5 cents each, dimes are worth 10 cents each, and quarters are worth 25 cents each.

You may assume that if you have an integer in the file, then a coin-type will follow it.

-------------------------------------------------------------------------------------------------------------------------

here is my code so far

import java.io.File;

import java.io.PrintWriter;

import java.util.ArrayList;

import java.util.Scanner;

public class CookieJar {

public static void cashingIn(File input, File output){

String penny;

String pennies;

String nickel;

String nickels;

String dime;

String dimes;

String quarter;

String quarters;

int p;

int n;

int d;

int q;

int cents = 0;

double dollars = cents / 100;

try{

// print writer to print to output

PrintWriter print = new PrintWriter(output);

// scanner to read input file

Scanner scan = new Scanner(input);

ArrayList list = new ArrayList();

while (scan.hasNext()){

// need to find a way to keep track of whether it's an int or currency

}

if(cents == 0){

print.println("You have no money in the jar");

}

else{

print.println("You have $" + dollars + " in the jar");

}

}

catch(Exception e){

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!