Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions