Question: Given the following Javascript program I wrote ( Homework 5 ) : class Product { constructor ( name , priceRange ) { this.name = name;

Given the following Javascript program I wrote (Homework 5):
class Product {
constructor(name, priceRange){
this.name = name;
this.priceRange = priceRange;
}
getPriceRange(){
return this.priceRange;
}
}
class ElectronicsProduct extends Product {
constructor(name, priceRange, warrantyPeriod, powerConsumption){
super(name, priceRange);
this.warrantyPeriod = warrantyPeriod;
this.powerConsumption = powerConsumption;
}
getWarrantyPeriod(){
return this.warrantyPeriod;
}
getPowerConsumption(){
return this.powerConsumption;
}
}
// Testing the classes
let objProduct = new Product("Phone","$500");
let objElectronicsProduct = new ElectronicsProduct("Laptop","$1000","2 years", "65.0W");
console.log("Product:");
console.log("Name:", objProduct.name);
console.log("Price Range:", objProduct.getPriceRange());
console.log("
Electronics Product:");
console.log("Name:", objElectronicsProduct.name);
console.log("Price Range:", objElectronicsProduct.getPriceRange());
console.log("Warranty Period:", objElectronicsProduct.getWarrantyPeriod());
console.log("Power Consumption:", objElectronicsProduct.getPowerConsumption());
The task is the following:
In Homework 5, You wrote a program on the inventory management system for a retail store
with 2 classes Product as the superclass and ElectronicsProduct as the subclass.
Modify the same program for exception handling. Please make sure to take all the values from the
user using scanner.
1.If the value entered from user is string or character in pricerange, it should show input mismatch
exception (2 points)
2. If warrantyperiod is <0 or >5, then output meaningful error message(s) if an exception occurs.
(2 points)
3.If power consumption is<2 digits, show exception error message, please enter correct number for
power consumption. (4 points)
4.Create a variable status in ElectronicsProduct class to store whether the product is available or not.
This variable stores yes or no values from the user. If the user enters any word (example null) other
than yes or no, show exception message. (2 points)

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!