Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CashRegister</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
14 changes: 14 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=16
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=16
10 changes: 10 additions & 0 deletions Input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
100 , 99
1,1
2,100
20,30
2.12,3.00
1.97,2.00
3.33,5.00
1.85,2.00
1.67,2.00
0.70,1.00
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Cash Register
============

This project is written in Java with a JUnit test class. It takes in a flat file with a list of prices and payments, and outputs the change, as a String, to a Receipt.txt file. In most cases, the least amount of physical change is returned, however, if the total due in cents is divisible by 3, the application randomly generates the change denominations. Below is the original problems and criteria for the application.


The Problem
-----------
Creative Cash Draw Solutions is a client who wants to provide something different for the cashiers who use their system. The function of the application is to tell the cashier how much change is owed and what denominations should be used. In most cases the app should return the minimum amount of physical change, but the client would like to add a twist. If the total due in cents is divisible by 3, the app should randomly generate the change denominations (but the math still needs to be right :))
Expand Down
10 changes: 10 additions & 0 deletions Receipt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Insufficient Funds
Exact Change Given
1 FIFTIES. 2 TWENTIES. 1 FIVE(S). 3 ONE(S).
1 TEN(S).
3 QUARTER(S). 1 DIME(S). 3 PENNIES.
3 PENNIES.
1 ONE(S). 2 QUARTER(S). 1 DIME(S). 1 NICKEL(S). 2 PENNIES.
3 NICKEL(S).
33 PENNIES.
6 NICKEL(S).
2 changes: 2 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/test/
/Register/
Binary file added bin/io/MoneyReader.class
Binary file not shown.
Binary file added bin/io/MoneyWriter.class
Binary file not shown.
228 changes: 228 additions & 0 deletions src/Register/Change.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
package Register;

import java.text.DecimalFormat;

/**
* The Change class calculates how much of each bill and coin
* are needed to makeup the change to be given back.
*
* @author chasekeady
*
*/
public class Change {
private int hundreds;
private int fifties;
private int twenties;
private int tens;
private int fives;
private int ones;
private int quarters;
private int dimes;
private int nickels;
private int pennies;
private String cashBack;
private DecimalFormat df;


/**
* Standard constructor for the Change class
*
* @param df - formats doubles in class to 2 decimal places
*/
public Change(DecimalFormat df){
this.df = df;
}

/**
* Calculates how many hundred dollar bills are needed to make the change
* to be given back. Returns how much change is left after hundred dollar
* bills are accounted for.
*
* @param change - amount needed to be returned
*/
public double hundreds(double change) {
if((int)(change/100) > 0){
hundreds = (int)(change/100);
change = Double.valueOf(df.format(change - (hundreds * 100)));
}
return change;
}

/**
* Calculates how many fifty dollar bills are needed to make the change
* to be given back. Returns how much change is left after fifty dollar
* bills are accounted for.
*
* @param change - amount needed to be returned
*/
public double fifties(double change) {
if((int)(change/50) >0){
fifties = (int)(change/50);
change = Double.valueOf(df.format(change - (fifties * 50)));
}
return change;
}

/**
* Calculates how many twenty dollar bills are needed to make the change
* to be given back. Returns how much change is left after twenty dollar
* bills are accounted for.
*
* @param change - amount needed to be returned
*/
public double twenties(double change) {
if((int)(change/20) >0){
twenties = (int)(change/20);
change = Double.valueOf(df.format(change - (twenties * 20)));
}
return change;
}

/**
* Calculates how many ten dollar bills are needed to make the change
* to be given back. Returns how much change is left after ten dollar
* bills are accounted for.
*
* @param change - amount needed to be returned
*/
public double tens(double change) {
if((int)(change/10) >0){
tens = (int)(change/10);
change = Double.valueOf(df.format(change - (tens * 10)));
}
return change;
}

/**
* Calculates how many five dollar bills are needed to make the change
* to be given back. Returns how much change is left after five dollar
* bills are accounted for.
*
* @param change - amount needed to be returned
*/
public double fives(double change) {
if((int)(change/5) >0){
fives = (int)(change/5);
change = Double.valueOf(df.format(change - (fives * 5)));
}
return change;
}

/**
* Calculates how many one dollar bills are needed to make the change
* to be given back. Returns how much change is left after one dollar
* bills are accounted for.
*
* @param change - amount needed to be returned
*/
public double ones(double change) {
if(change-1 >= 0) {
ones = 0;
while(change >= 1) {
change = Double.valueOf(df.format(change -1));
ones++;
}
}
return change;
}

/**
* Calculates how many quarters are needed to make the change
* to be given back. Returns how much change is left after the
* quarters are accounted for.
*
* @param change - amount needed to be returned
*/
public double quarters(double change) {
if((int)(change/.25) > 0) {
quarters = (int)((change*100)/(.25*100));
change = Double.valueOf(df.format(change - (quarters * .25)));
}
return change;
}

/**
* Calculates how many dimes are needed to make the change
* to be given back. Returns how much change is left after the
* dimes are accounted for.
*
* @param change - amount needed to be returned
*/
public double dimes(double change) {
if((int)(change/.10) > 0) {
dimes = (int)((change*100)/(.10*100));
change = Double.valueOf(df.format(change - (dimes * .10)));
}
return change;
}

/**
* Calculates how many nickels are needed to make the change
* to be given back. Returns how much change is left after the
* nickels are accounted for.
*
* @param change - amount needed to be returned
*/
public double nickels(double change) {
if((int)(change/.05) > 0) {
nickels = (int)((change*100)/(.05*100));
change = Double.valueOf(df.format(change - (nickels * .05)));
}
return change;
}

/**
* Calculates how many pennies are needed to make the change
* to be given back. Returns how much change is left after the
* pennies are accounted for.
*
* @param change - amount needed to be returned
*/
public double pennies(double change) {
if((int)(change/.01) > 0) {
pennies = (int)(change/.01);
change = change - (pennies * .01);
}
return change;
}

/**
* Returns a string that contains the bills and coins that makeup
* the change needed to be handed back.
*/
public String printChange() {
cashBack = "";
if(hundreds != 0){
cashBack += hundreds + " HUNDRED(S). ";
}
if(fifties != 0){
cashBack += fifties + " FIFTIES. ";
}
if(twenties != 0){
cashBack += twenties + " TWENTIES. ";
}
if(tens != 0){
cashBack += tens + " TEN(S). ";
}
if(fives != 0){
cashBack += fives + " FIVE(S). ";
}
if(ones != 0){
cashBack += ones + " ONE(S). ";
}
if(quarters != 0){
cashBack += quarters + " QUARTER(S). ";
}
if(dimes != 0){
cashBack += dimes + " DIME(S). ";
}
if(nickels != 0){
cashBack += nickels + " NICKEL(S). ";
}
if(pennies != 0){
cashBack += pennies + " PENNIES. ";
}

return cashBack;
}
}
Loading