ques - Create Product having following attributes: Product ID, Name, Category ID and UnitPrice. Create ElectricalProduct having the
following additional attributes: VoltageRange and Wattage. Add a behavior to change the Wattage and price of the electrical
product. Display the updated ElectricalProduct details.
program made by me-
import java.io.*;
class Product
{
int productId;
String productName;
int categoryId;
double unitPrice;
Product(double a)
{
unitPrice = a;
}
}
class ElectricalProduct extends Product
{
int voltageRange;
int wattage;
void changeWattage(int watt)
{
wattage = watt;
}
void changePrice(double b)
{
super(b);
}
void show()
{
System.out.println("The Product ID is : " +productId);
System.out.println("The Product NAME is : " +productName);
System.out.println("The Category ID is : " +categoryId);
System.out.println("The Voltage Range is : " +voltageRange);
System.out.println("The Change Wattage is : " +wattage);
System.out.println("The Change UnitPrice is : " +unitPrice);
}
}
class NewProduct
{
public static void main(String [] args) throws IOException
{
double newprice;
int w;
Product p = new Product();
ElectricalProduct ep = new ElectricalProduct();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Product ID : ");
p.productId = Integer.parseInt(br.readLine());
System.out.println("Enter the Product Name : ");
p.productName = br.readLine();
System.out.println("Enter the Category ID : ");
p.categoryId = Integer.parseInt(br.readLine());
System.out.println("Enter the Unit Price : ");
p.unitPrice = Double.parseDouble(br.readLine());
System.out.println("Enter the Voltage Range : ");
ep.voltageRange = Integer.parseInt(br.readLine());
System.out.println("Enter the New Wattage : ");
w = Integer.parseInt(br.readLine());
ep.changeWattage(w);
System.out.println("Enter the New Unit Price : ");
newprice = Double.parseDouble(br.readLine());
ep.changePrice(newprice);
System.out.println("The UPDATED ELECTRICAL PRODUCT DETAILS ARE ");
ep.show();
}
}
rectify the errors in this program...

