-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest.java
More file actions
44 lines (32 loc) · 1.32 KB
/
Test.java
File metadata and controls
44 lines (32 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**Filename: Test
* @version:1.0
* @author: Mwiche Dina Nachilongo 202208650
* Program to: Test custom exception for subclasses (LimitExceededException)
* To compile: javac Test.java
* To execute: java Test
*/
import java.util.Scanner;
public class Test {
public static void main (String[] args) throws LimitExceededException{
Scanner till = new Scanner (System.in);
Fruit f1 = new Fruit("apple", 800.0, false);
Meat m1 = new Meat("beef", 400.0, "loin"); //instantiate objects from sub-classes
Fruit f2= new Fruit("banana", 600.00, false);
Meat m2 = new Meat("pork", 700.00, "belly");
System.out.println("***Catalogue of items in stock***");
f1.displayInfo();
f2.displayInfo(); //Print out objects instantiated
m1.displayInfo();
m2.displayInfo();
System.out.println("Select desired weight of fruit or meat in catalogue to validate: "); //Prompt user input
double weight = till.nextDouble();
weightValidation(weight);
till.close();
}
//Create method to validate whether the parameter (weight) meets limit criterion
private static void weightValidation( double weight) throws LimitExceededException {
if (weight > 10) {
throw new LimitExceededException("Select a weight below 10kg please!");
}
}
}