Use JAVA Lane Router Your supermarket has become the model of efficiency. Before
ID: 3585492 • Letter: U
Question
Use JAVA
Lane Router Your supermarket has become the model of efficiency. Before checking out, you now enter a lane router which scans the number of items in your cart, then routes you to the appropriate checkout lane. The routing is as follows: Lane 1 Less than 4 items Lane 2:Either 5 or 7 items Lane 3:Either 6, 9, or 10 items Lane 4:8 items Lane 5:All others Write a class called LaneRouter with method route that takes an int argument containing the number of items in your cart. The route method uses a switch statement to print the lane to which you have been assigned. Call the route method from main using several different itenmExplanation / Answer
public class LaneRouter{
int route(int itemcount){
switch(itemcount){
case 1: return 1;
case 2: return 1;
case 3: return 1;
case 4: return 1;
case 5: return 2;
case 7: return 2;
case 8: return 4;
case 6: return 3;
case 9: return 3;
case 10: return 3;
default: return 5;
}
}
public static void main(String args[]){
LaneRouter lr = new LaneRouter();
for(int i=1;i<12;i++){
System.out.println("Itemcount:" + i +" , Lane: " + lr.route(i));
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.