Answer:
Check the explanation
Step-by-step explanation:
Given below is the code for the question.
import java.util.*;
public class PlaceAnOrder
{
public static void main(String[] args)
{
final int HIGHITEM = 9999;
final int HIGHQUAN = 12;
int code;
int x;
boolean found;
final int[] ITEM = {111, 222, 333, 444};
final double[] PRICE = {0.89, 1.47, 2.43, 5.99};
int item;
int quantity;
double price = 0;
double totalPrice = 0;
Scanner input = new Scanner(System.in);
try{
System.out.print("Enter Item number: ");
if(input.hasNextInt()){
item = input.nextInt();
if(item < 0)
throw new OrderException(OrderMessages.message[2]);
if(item > HIGHITEM)
throw new OrderException(OrderMessages.message[3]);
System.out.print("Enter Item quantity: ");
if(input.hasNextInt()){
quantity = input.nextInt();
if(quantity < 1)
throw new OrderException(OrderMessages.message[4]);
if(quantity > HIGHQUAN)
throw new OrderException(OrderMessages.message[5]);
found = false;
for(int i = 0; i < ITEM.length; i++){
if(ITEM[i] == item){
found = true;
totalPrice = PRICE[i] * quantity;
break;
}
}
if(!found)
throw new OrderException(OrderMessages.message[6]);
System.out.println("Total Amount due: $" + totalPrice);
}
else
throw new OrderException(OrderMessages.message[1]);
}
else
throw new OrderException(OrderMessages.message[0]);
}catch(OrderException e){
System.out.println(e.getMessage());
}
}
}