Computers and Technology

The Product class has a productID and a price. It also has a method getProductID() as shown in the code below. public class Product{ private String productID; private double price; public Product(String productID, double price){ //implementation not shown } public boolean canReplace(Product p){ //implementation not shown } //other instance variables, constructors and methods are not shown}public class Widget extends Product{private String productionDate;public Widget(String id, String pd, double price){//to be implemented in part a}}A Widget is a Product and has a productID and price. The productID is a unique string for each product. No two productID's are the same. Given the following code, Product p1 = new Product("341-1101", 129.99);Product p2 = new Widget("82794-mach10q", "12/7", 89.99);Widget w1 = new Widget("123-AB307", "12.7", 109.95);Part A: A Widget is a product. A Widget has an identifier, a productionDate and a Price. The productID of a Widget is the combination of the identifier and productionDate. Product p2 = new Widget("82794-mach10q", "12/7", 89.99);P2 has an identifier of "82794-mach10q" and productionDate of "12/7". Therefore it's productID is: "82794-mach10q_12/7".The Write the constructor for the Widget class. Part B: The canReplace() method determines if one product can be replaced by another. A Product can only be replaced when the identifier of the parameter productID is greater than the identifier of the calling object and when the price of the parameter product is greater than the price of the calling object. Thus p1.canReplace(p2) is false because the price of p2 is less than the price of p1.And p2.canReplace(w1) is false because the productID for w1 comes before the productID of p2.But w1.canReplace(p1) is true because the productID for p1 comes after the productID for w1 and the price w1 is less than the price of p1.Write the canReplace() method for the Product class below.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:50, nicoleskertich
You have written, as part of a school assignment, a research paper on the solar system. you want to share this paper on your school website. on which type of server will you upload it?
Answers: 1
image
Computers and Technology, 24.06.2019 17:40, lia1690
Which of the following processes applications across multiple computing devices? a. functional application b. distributed system c. workgroup information silo d. information silo
Answers: 3
image
Computers and Technology, 24.06.2019 20:30, glstephens04
How is energy expended in active transport
Answers: 1
image
Computers and Technology, 25.06.2019 08:40, lflugo6oyn4sp
Which of the following statements is incorrect in relation to processes: while, strictly speaking, at any instant of time, the cpu is running only one process, in the course of 1 second, it may work on several of them, giving the illusion of parallelism a process is just an instance of an executing program, including the current values of the program counter, registers, and variables processes can be created when an operating system is booted, created by the user, or a running process can create children processes there is a master process, which when started can last forever, and is not killable
Answers: 3
Do you know the correct answer?
The Product class has a productID and a price. It also has a method getProductID() as shown in the c...

Questions in other subjects:

Konu
Chemistry, 07.02.2022 09:00