Question: public static void main ( String [ ] args ) { / / Scanner for user input Scanner scanner = new Scanner ( System .

public static void main(String[] args){
// Scanner for user input
Scanner scanner = new Scanner(System.in);
//1. Default Constructor Case
Apple appleDefault = new Apple();
System.out.println("Default Constructor: "+ appleDefault.toString());
//2. Parameterized Constructor with Valid Type
Apple apple1= new Apple("Red Delicious", 1.5,2.99);
System.out.println("Parameterized Constructor (Valid Type): "+ apple1.toString());
//3. Parameterized Constructor with Invalid Type
Apple apple2= new Apple("Invalid Type", 1.0,1.99);
System.out.println("Parameterized Constructor (Invalid Type): "+ apple2.toString());
//4. Setting Weight within Valid Range
apple1.setWeight(1.2);
System.out.println("Set Weight (Valid): "+ apple1.getWeight());
//5. Setting Weight Outside Valid Range
apple1.setWeight(3.0);
System.out.println("Set Weight (Invalid): "+ apple1.getWeight());
//6. Setting Price to Valid Value
apple1.setPrice(3.50);
System.out.println("Set Price (Valid): "+ apple1.getPrice());
//7. Setting Price to Invalid Value
apple1.setPrice(-2.00);
System.out.println("Set Price (Invalid): "+ apple1.getPrice());
//8. toString Method
System.out.println("toString Method: "+ apple1.toString());
//9. Equality Check with Same Properties
Apple apple3= new Apple("Red Delicious", 1.5,2.99);
System.out.println("Equality Check (Same Properties): "+ apple1.equals(apple3)); // true
//10. Equality Check with Different Properties
System.out.println("Equality Check (Different Properties): "+ apple1.equals(apple2)); // false
// Close the scanner
scanner.close();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!