Concept explainers
Challenge exercise Implement a method in StockManager to print details of all products with stock levels below a given value (passed as a parameter to the method).
Modify the addProduct method so that a new product cannot be added to the product list with the same ID as an existing one.
Add to StockManager a method that finds a product from its name rather than its ID:
public Product findProduct (String name)
In order to do this, you need to know that two String objects, s1 and s2, can be tested for equality with the boolean expression
S1. equals (s2)
More details about comparing Strings can be found in Chapter 6.
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Additional Engineering Textbook Solutions
Java How To Program (Early Objects)
Starting Out with C++: Early Objects
Artificial Intelligence: A Modern Approach
Computer Science: An Overview (12th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- Implement the following class. Refer to the below notes for more details. SimCard phoneNumber: String internationalService: boolean minutes: int // default 0 costPerMinute: double + SimCard ( ) + SimCard ( newPhoneNumber: String, newInternationalService: boolean ) + getters and setters of phoneNumber, internationalService and costPerMinute + callLocal (duration: int): void + callInternational(duration: int): boolean + bill(): double o phoneNumber: private String representing the phone number. Default is "00-000000" o internationalService : private boolean indicating whether international calls are allowed or not. Default is false. o minutes: private int representing the number of minutes to be invoiced (added to the bill). Default is 0. o costPerMinute: private double representing the cost of 1 minute. This value should be positive. Default value is 0.2. Assume all the sim card has the same cost rate per minute. LS) The no-arg constructor that will create a new SimCard with the default…arrow_forwardin Jave create two methods work(), and interwork() with the follow instructions: You may assume that the work() method is passed a List that does not contain any null elements. (Note: The List may contain missing elements.) The work() method must not have any side effects. That is, it must not change the parameters that it is passed in any way and it must not change any attributes in any way. The work() method must return the weighted average of the elements in the List it is passed. The label of the result must equal the parameter named rl. The data parameter contains the values to use in the calculation. If an element of data is missing (i.e., has a value attribute that is null) then that element must be ignored in the calculation. The weights attribute contains the weights to use in the calculation. If the weights attribute is null then all weights used in the calculation must be 1. You may assume that all of the elements of weights (if it is non-null) are…arrow_forwardin Jave create two methods work(), and interwork() with the follow instructions: You may assume that the work() method is passed a List that does not contain any null elements. (Note: The List may contain missing elements.) The work() method must not have any side effects. That is, it must not change the parameters that it is passed in any way and it must not change any attributes in any way. The work() method must return the weighted average of the elements in the List it is passed. The label of the result must equal the parameter named rl. The data parameter contains the values to use in the calculation. If an element of data is missing (i.e., has a value attribute that is null) then that element must be ignored in the calculation. The weights attribute contains the weights to use in the calculation. If the weights attribute is null then all weights used in the calculation must be 1. You may assume that all of the elements of weights (if it is non-null) are…arrow_forward
- True or False: When numerous parameters are supplied to a method, the order in which they are passed is irrelevant.arrow_forwardWrite the method header for the ShowRetailPrice method. A list price and a markup % should be parameter variables in the procedure. Create a method with a default markup percentage of 50% as the default parameter.arrow_forwardComplete the convert() method that casts the parameter from a double to an integer and return Note that the main() method prints out the returned value of the convert() method. Ex: If the double value is 19.9, then the output is: 19 Ex: If the double value is 3.1, then the output is: 3 512334.3517088.qx3zqy7 LAB ACTIVITY 1 public class LabProgram { 2 NM & in 3 public static int convert(double d) { /* Type your code here */ 4 5 6 7 } 25.20.1: LAB: Write convert() method to cast double to int 8 public static void main(String[] args) { System.out.println(convert (19.9)); System.out.println(convert(3.1)); 00 00 9 10 11 } 12 } LabProgram.javaarrow_forward
- Take a look at the header of the method below, and then implement a sample call to it in your code.empty public ShowValue ()arrow_forwardAn alternative approach to creating methods using heredocs.arrow_forwardFinish the TestPlane class that contains a main method that instantiates at least two Planes. Add instructions to instantiate your favorite plane and invoke each of the methods with a variety of parameter values to test each option within each method. To be able to test the functionality of each phase, you will add instructions to the main method in each phase.arrow_forward
- Complete the Car class by creating an attribute purchase_price (type int) and the method print_info() that outputs the car's information. Ex: If the input is: 2011 18000 2018 where 2011 is the car's model year, 18000 is the purchase price, and 2018 is the current year, then print_info() outputs: Car's information: Model year: 2011 Purchase price: 18000 Current value: 5770arrow_forwardComplete the Car class by creating an attribute purchase_price (type int) and the method print_info() that outputs the car's information. Ex: If the input is: 2011 18000 2018 where 2011 is the car's model year, 18000 is the purchase price, and 2018 is the current year, then print_info() outputs: Car's information: Model year: 2011 Purchase price: $18000 Current value: $5770 Note: print_info() should use two spaces for indentation.arrow_forwardcreate java method to count the number of employees and their salary ranges according to your assumptions. You can think about any assumption . Create main class to call the methodarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education