Question: Create a new Java project called inlab4. 2. Create a package called model and a package called test. 3. In the model package, add the

Create a new Java project called inlab4. 2. Create a package called model and a package called test. 3. In the model package, add the following class: package model; public class Laptop { private String maker; private double price; private static int numberOfLaptops; public Laptop(String maker, double price) { this.maker = maker; this.price = price; numberOfLaptops++; } public String getMaker() { return maker; } public double getPrice() { return price; } public void setMaker(String maker) { this.maker = maker; } public void setPrice(double price) { if (price<0) this.price = price; else this.price = 0; } public String toString(){ return String.format("Marker: %s, Price: QR%.2f", maker,price); } } 4. In the model, add a class called Person that contains three data fields: id (int), name (String) and laptop (Laptop). Your class should have a constructor that initializes the three instance variables. Provide the setter and the getter method for each instance variable. a) Add a method called hasLaptop() that returns true if the laptop instance variable is not null and returns false otherwise.

b) Add a toString() method that returns the person name and all the information about his/her laptop but only if the student has a laptop (hint: use hasLaptop()). If the person doesnt have a laptop then the method returns only the name of the student. 5. In the test package of your project create another Java class called personTest that includes a main()method in which you do the following (in the given sequence):

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 Databases Questions!