You can use any programming language whatever you like (Java, C, C++).. Kuru : P
ID: 3850027 • Letter: Y
Question
You can use any programming language whatever you like (Java, C, C++)..
Kuru : Penny, Lira : Currency
Consider the following program description: "Write a program that determines the change to be dispensed from a vending machine. An item in the machine can cost between 50 kurus and 2 liras, in 25 kurus increments (50, 75, 100,..., 150, 175, 200), and the machine only accepts one lira coins to pay for the item. The machine accepts a maximum of 2 one lira coins. The change should be in as less coins as possible using 1 lira, 50 and 25 kurus coins. For instance, a possible dialogue with the user might be: Enter the price of the item in kurus: 125 Enter the number of 1 lira coins you have inserted into the machine: 2 You bought an item for 125 kurus and gave me 2 liras, so your change is Kurus Penny Lira Currency 0 1 lira 1*50 kurus 1*25 kurus Display the change only if a valid price or a valid number of coins is entered (no less than 50 kurus, no more than 200 kurus, an integer multiple of 25 kurus, and inserted 1 or 2 one lira coins). Otherwise display a separate error message for any of the following invalid inputs: a cost under 50 kurus a cost more than 200 kurus a cost that is not a multiple of 25 kurus less than one 1 lira coin more than 2 lira coins For the above description: 1. Develop a program using a language of your choice 2. Derive equivalence classes. 3. Apply boundary values analysis. 4. Generate test cases. 5. Implement unit tests for the test cases you have generated in step 4 Submit 1. A report of the equivalence classes you have derived, boundary value analysis and test cases (input and the expected output) with an explanation of how you have derived them 2. Source code (both the program and the unit tests) 3. A screenshot showing that all of your tests are successfulExplanation / Answer
public class VendingMachine {
public void dispenseCoins(int liracoins,int cost)
{
if(liracoins>2)
{
throw new IllegalArgumentException("more than 2 lira coins");
}
else if(liracoins<1)
{
throw new IllegalArgumentException("less than 1 lira coins");
}
else if(cost%25!=0)
{
throw new IllegalArgumentException("cost not a multiple of 25 ");
}
else if(cost>200)
{
throw new IllegalArgumentException("cost is greater than 200 kurus");
}
else if(cost<50)
{
throw new IllegalArgumentException("cost under 50 kurus");
}
else
{
int diff=liracoins*100-cost;
int lirachange=0;
int kuru_50_change=0;
int kuru_25_change=0;
int x=0;
int y=0;
lirachange=diff/100;
x=diff%100;
kuru_50_change=x/50;
y=x%50;
kuru_25_change=y/25;
System.out.println(lirachange+"*1 lira "+kuru_50_change+"*50 kurus "+kuru_25_change+"*25 kurus ");
}
}
}
------------------------------------
package dispenser;
import java.util.Scanner;
public class Driver {
public static void main(String args[])
{
int cost=0;
int liracoins=0;
VendingMachine m=new VendingMachine();
Scanner read=new Scanner(System.in);
try {
System.out.print("enter the price of item in kurus: ");
cost=read.nextInt();
System.out.println();
System.out.print("enter the number of lira coins you have inserted in machine: ");
liracoins=read.nextInt();
System.out.println(String.format("you bought an item of %d and gave me %d lira coins so your change is",cost,liracoins));;
m.dispenseCoins(liracoins, cost);
} catch (Exception e) {
// TODO: handle exception
System.out.println(e.getMessage());
}
finally
{
read.close();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.