Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have 2 errors in my code can you please fix it. package model; public class VendingMachine { String status; int coke; int orangeJuice; int

I have 2 errors in my code can you please fix it.

image text in transcribedimage text in transcribed

package model;

public class VendingMachine {

String status; int coke; int orangeJuice; int kitkat; int lays; int total;

//constructor public VendingMachine(){ status = "Empty VM Started"; coke = 0; orangeJuice = 0; kitkat = 0; lays = 0; total = 0; }

public String checkStatus(){ return status; }

public String checkStock(){ String result = "Stock: Coke (" + coke + "), Orange Juice (" + orangeJuice + "), Kitkat Chunky Bar (" + kitkat + "), Lay's Classic Chips (" + lays + ")"; return result; }

public void add(String product, int units){ switch(product){ case "Coke": coke += units; status = "Product added: Coke (" + units + ")"; total += units; break; case "Orange Juice": orangeJuice += units; status = "Product added: Orange Juice (" + units + ")"; total += units; break; case "Kitkat Chunky Bar": kitkat += units; status = "Product added: Kitkat Chunky Bar (" + units + ")"; total += units; break; case "Lay's Classic Chips": lays += units; status = "Product added: Lay's Classic Chips (" + units + ")"; total += units; break; default: status = "Invalid product: "+product;

} }

public void dispense(String product, int units){ switch(product){ case "Coke": coke -= units; status = "Product removed: Coke (" + units + ")"; total -= units; break; case "Orange Juice": orangeJuice -= units; status = "Product removed: Orange Juice (" + units + ")"; total -= units; break; case "Kitkat Chunky Bar": kitkat = units; status = "Product removed: Kitkat Chunky Bar (" + units + ")"; total -= units; break; case "Lay's Classic Chips": lays -= units; status = "Product removed: Lay's Classic Chips (" + units + ")"; total -= units; break; default: status = "Invalid product: "+product;

} }

public String checkStock(String product){ String result; switch(product){ case "Coke": result = "Coke (" + coke + ")"; break; case "Orange Juice": result = "Orange Juice (" + orangeJuice + ")"; break; case "Kitkat Chunky Bar": result = "Kitkat Chunky Bar (" + kitkat + ")"; break; case "Lay's Classic Chips": result = "Lay's Classic Chips (" + lays + ")"; break; default: result = "Invalid product: "+product;

}

return result; }

}

EECS1022-W21-workspace - EECS1022_W21_Lab5/src/junit_tests/TestVending Machine.java - Eclipse IDE File Edit Source Refactor Navigate Search Project Run Window Help * Debug Project Explorer JUnit X Finished after 0.152 seconds Runs: 10/10 Errors: 0 Failures: 2 211 . at junit_tests. Test Vending Machine (Runner: JUnit 4] (0.060 test_Vending Machine_01a (0.001 s) test_Vending Machine_01c (0.000 s) test_Vending Machine_02 (0.001 s) test_Vending Machine_03 (0.052 s) test_Vending Machine_04 (0.001 s) test_Vending Machine_01b1 (0.001 s) test_Vending Machine_0162 (0.000 s) test_Vending Machine_0163 (0.000 s) test_Vending Machine_0164 (0.001 s) test_Vending Machine_01b5 (0.003 s) > TestVending Machine.java X D Vending Machine.java 206 Result Comparison x, result); 207 208 test_Vending Machine_03 (junit_tests. TestVending Machine) DI A4 209 210 Expected Actual Kitkat Chunky Bar (4) Kitkat Chunky Bar (3) 212 213 214 :" and before the opening p 215 216 217 218 219 220 , result); 221 222 223 OK 224 225 vm.dispense("Kitkat Chunky Bar", 3); // this changes the status 226 227 result = vm.checkStatus(); 228 assertEquals("Product removed: Kitkat Chunky Bar (3)", result); // Notice the space after the colon ":" and before the open 229 230 result = vm.checkStock("Kitkat Chunky Bar"); 231 assertEquals("Kitkat Chunky Bar (4)", result); 232 233 result = vm.checkStock(); 234 assertEquals("Stock: Coke (4), Orange Juice (4), Kitkat Chunky Bar (4), Lay's Classic Chips (8)", result); 235 236 237 * Remove stock of Lay's Classic Chips 238 239 vm.dispense("Lay's Classic Chips", 4); // this changes the status 240 241 result = vm.checkStatus(); 242 assertEquals("Product removed: Lay's Classic Chips (4)", result); // Notice the space after the colon ":" and before the op 243 244 result = vm.checkStock("Lay's Classic Chips"); 245 assertEquals("Lay's Classic Chips (4)", result); 246 247 result = vm.checkStock(): Failure Trace Jorg.junit.ComparisonFailure expected:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions