public class Change { // declare variable to store data private String name; private int amount; // default constructor public Change() { this.name = ""; this.amount = 0; } // parameterized constructor public Change(String name) { this.name = name; // to accepts specific numbers of parameter this.amount = amount; // and initialise data members of a class with distinct values } // getters method public String getName() { return name; } public int getCoin() { return amount; } // setters method public void setName(String name) { this.name = name; } public void setCoin(int amount){ this.amount = amount; } // calculate and to return denomination count public int[] calculate(){ int Dollar, FiftyCent, TwentyFiveCent, TenCent, FiveCent; // formula to calculate declared instance Dollar = amount / 100; FiftyCent = (amount % 100) / 50; TwentyFiveCent = ((amount % 100) % 50) / 25; TenCent = ((amount % 100) % 25) / 10; FiveCent = ((((amount % 100) % 50) %25) % 10) / 5; int denomination[] = {Dollar, FiftyCent, TwentyFiveCent, TenCent, FiveCent}; return denomination; } }
import java.util.Scanner; public class ChangeMain { public static void main(String[] args) { int amount, min, max, index; String name; char people; boolean newUser; Scanner keyboard = new Scanner(System.in); System.out.println("Recommendation: Please enter at least 10 records to test the program. "); while(newUser = true){ // prompt user to enter 10 records of name // to save the instance in the array System.out.println("Please enter the user name: "); name = keyboard.nextLine(); // to print the amount and allow user to know value is valid when divisible by 5 // prompt user to enter coin value System.out.println("Please enter the user coin value: "); amount = keyboard.nextInt(); keyboard.nextLine(); if(amount < 5 || amount > 100 || (amount % 5) != 0) // modulus operator for divisor of 5 { System.out.println("Invalid Value! Please enter the value (multiple of 5) again!"); } else { System.out.println("***** Proceed to continue with the program! *****"); } // to break the loop when user enter "N" System.out.println("Do you have more user to enter[Y/N]: "); String userInput = keyboard.nextLine(); if(userInput.equalsIgnoreCase("N")) { System.out.println("Program exit....."); break; } } } }
if(amount < 5 || (amount % 5) != 0) // if less than 5 or not a multiple
//create empty array of Change objects type Change[] changes = ... int idx = ... in loop: //create Change object Change change = ... (set it) //store this object changes[idx++] = change;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)