Question: Create a java package called Laptops. 1. Create Main.java as follows import laptops.*; public class Main { /* * ---------------------------------------------------------------- -------- * Task: Follow the

Create a java package called Laptops.

1. Create Main.java as follows

import laptops.*; 
public class Main { /* 
 * ---------------------------------------------------------------- -------- 
 * Task: Follow the steps described below, and gradually uncomment the 
 * snippets of code below the CHECK YOUR CODE tag, one by one, to check 
 * your implementation of classes. 
 * ---------------------------------------------------------------- -------- 
 * 0. Make sure you maintain the project architecture as it is: 
 * (default package) --> Main.java 
 * laptop --> Laptop.java, Mac.java, Lenovo.java 
 * * 1. Start with the class 'Laptop' and complete it. * * 2. Create another class, 'Mac'\ * 2.1. This class inherits everything from 'Laptop'. (It 
extends 'Laptop'.) *2.2. This class should have one additional field; for 
Macbooks, we need * a field to indicate the model, whether it is a "-", 
"pro", or "air". * 2.3. Make sure all constructors and methods work 
properly with the new *field as well. 
 * 3. Create yet another class, 'Lenovo', also extending 'Laptop'. 
 * 3.1. This clss inherits everything from 'Laptop'. (It extends 'Laptop'.) 
 * 3.2. This class should have one additional field; for Lenovo laptops we 
 * need a field which indicates which operating system this device comes 
 * with. It could be Windows, Linux, Chrome, or None. 
 * 3.3. Make sure all the constructors and methods work properly with the new 
 * field as well. 
 * 4. Make sure onc cannot create an object of type 'Laptop'. Only 'Mac' or 'Lenovo' 
 * objects can be created. */ 
 double myMacPrice = 1800; double myMacWeight = 2.03; double myMacScreen = 12.0; String myMacModel = "air"; 
 double myLenovoPrice = 1650; double myLenovoWeight = 2.45; 
 double myLenovoScreen = 12.4; String withOS = "Linux"; //+++++++++++++++++++++++ CHECK YOUR CODE +++++++++++++++++ 

++++++++ /*

 Laptop myLaptop = new Mac(); myLaptop.info(); */ /* 
 myLaptop = new Mac(myMacPrice, myMacWeight, myMacScreen, myMacModel); 
 myLaptop.info(); */ /* Laptop myLenovoLaptop = new Lenovo(); myLenovoLaptop.info(); 
 */ /* myLenovoLaptop = new Lenovo(myLenovoPrice, myLenovoWeight, 
myLenovoScreen, withOS); myLenovoLaptop.info(); */ 

}

2. Create Package Called Laptops 3. Create Classes as follows 

4. Create Laptop.java package laptops;

Laptop.java;

Lenovo.Java;

Mac.java;

public class Laptop { /****************************************** 

* FIELDS

 *******************************************/ double price; double weight; double screenSize; /****************************************** 
 * CONSTRUCTOR 
 *******************************************/ /* 
 * Add the constructors here * */ 
 /****************************************** * METHODS *******************************************/ 
 /* * Add a method to print all the information (fields) * */ 

}

 **************************************************************** INHERITANCE 
**************************************************************** 

5. Create Lenovo.java package laptops; public class Lenovo extends Laptop {

 /****************************************** * FIELDS 

 *******************************************/ /* 
 * Add the fields here * (For Lenovo laptops we need a field which indicates * which operating system this device comes with.) */ 
 /****************************************** * CONSTRUCTOR *******************************************/ 
 /* * Add the constructors here * */ 
 /****************************************** * METHODS *******************************************/ 
 /* * Add a method to print all the information (fields) * */ 

}

6. Create Mac.java package laptops; public class Mac extends Laptop {

 /****************************************** * FIELDS *******************************************/ 
 /* * Add the fields here * (For Macbooks, we need a field to indicate the model * whether this model is a "-", "pro", or "air".) */ 
 /****************************************** * CONSTRUCTOR 
*******************************************/ /* 
 * Add the constructors here * */ 
 /****************************************** * METHODS *******************************************/ 
 /* * Add a method to print all the information (fields) * */ 

}

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!