Question

In: Computer Science

JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz...

JAVA PROGRAM:

INCLUDE COMMENTS EXPLAINING THE CODE PLEASE

Given the following information:

  • 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 128GB PCIe-based flash storage
  • 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 256GB PCIe-based flash storage
  • 15.6-inch Dell i3552, 1.6GHz Processor, Intel Pentium N3700, HD Laptop, 4 GB memory, DDR3L SDRAM, Windows 10, Black

Drive 3 classes; class Computer (a super class), class Apple and class Others (subclasses). Your classes should have whatever variables you think needed to reflect the given information, think carefully what is needed to be assigned to the super class and what should be assigned to the sub classes.

Solutions

Expert Solution

We have one superclass Computer and two subclasses, Apple and Others. If we look at the given specification of the laptops, we notice 4 attributes that are common in both Apple and non-Apple laptops, so we keep those 4 attributes in Computer class. The non-common attributes will be kept in their corresponding specific classes. Below is the rough model of all the items and their class types.

Computer
=============
modelName
screenSize
processorSpeed
ramSize


Apple
=============
flashStorageSize
graphicsCard
turboBoostLimit
numberOfCores
processorGeneration


Others
=============
processorModel
isHd
ramType
operatingSystem
color

The code is divided in three separate files Computer.java, Apple.java, and Others.java. Each of the files has inline comments to explain the thought process and logic. I am pasting the code right below followed by the IDE screenshot of the same code and execution outputs.

Computer.java

package myStore;

/*
* The parent(super) class Computer
*/
public class Computer {
   /*
   * Computer has below 4 parameters common in
   * both Apple and non-Apple laptops
   * Hence, we will keep them in this class
   * and will re-use them in the subclasses
       =============
       modelName
       screenSize
       processorSpeed
       ramSize
      
   */

   protected String modelName; // MacBook Air or Dell i3552
   protected double screenSize;   // inches can be non-integer, so take it as double
   protected double processorSpeed;// Again it's a double value, 1.66GHz etc
   protected int ramSize; // It's an integer always, 4/8/16 GB etc.
  
   // Define a parameterized constructor, this will help the
   // object formation of subclasses Apple and Others
   public Computer(String model, double size, double speed, int ram) {
       this.modelName = model;
       this.screenSize = size;
       this.processorSpeed = speed;
       this.ramSize = ram;
   }
}

Apple.java

package myStore;

/*
* The subclass Apple which will inherit all
* the properties of superclass Computer,
* namely
*        modelName
       screenSize
       processorSpeed
       ramSize
* Apart from these, it has its own attributes
*/
public class Apple extends Computer {

   /*
   *
       Apple laptop specific attributes(which are not
       present in Other laptops)
       =============
       numberOfCores
       processorGeneration
       graphicsCard
       turboBoostLimit      
       flashStorageSize
   */
  
   private int flashStorageSize;       //Flash size in int, like 128GB etc
   private String graphicsCard;       //String like Intel HD Graphics 6k
   private double turboBoostLimit;       // It's a double, like 2.7GHz
   private int numberOfCores;           // if dual-core then 2, quad-core = 4
   private String processorGeneration;   // Core i5 ,i3 or i7
  
   /*
   * Apple constructor which takes the inherited attributes as well as
   * its own attributes to initialize an object of class "Apple"
   * First 4 parameters are coming from the superclass "Computer",
   * while rest are Apple specific parameters
   */
   private Apple(String model, double size, double speed, int ram,
               int flash, String graphics, double turbo,
               int cores, String generation) {
       // invoke the superClass constructor (Computer's)
       super(model, size, speed, ram);
       // Assign rest of Apple specific attributes
       this.flashStorageSize = flash;
       this.graphicsCard = graphics;
       this.turboBoostLimit = turbo;
       this.numberOfCores = cores;
       this.processorGeneration = generation;
   }

   public static void main(String args[]) {
       /*
       * Create an Apple-laptop object with all the necessary parameters, name it ap,
       * use ap to print the Apple-laptop's specifications in a formatted output
       *
       * 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor,
       * Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory,
       * 128GB PCIe-based flash storage
       */
       Apple ap = new Apple("MacBook Air", 13, 1.66, 8, 128, "Intel HD Graphics 6000", 2.7, 2, "Intel Core i5");
       System.out.println("------- Details of an Apple laptop --------\n"
               + "Model: " + ap.modelName
               + "\nScreen: " + ap.screenSize + " inches"
               + "\nProcessor Speed: " + ap.processorSpeed + " GHz"
               + "\nProcessor Type: " + ap.processorGeneration
               + "\nCores: " + ap.numberOfCores
               + "\nTurboBoost up to: " + ap.turboBoostLimit + " GHz"
               + "\nGraphics: " + ap.graphicsCard
               + "\nRAM: " + ap.ramSize + " GB"
               + "\nFlash: " + ap.flashStorageSize + " GB");
      
   }

}

Others.java

package myStore;
/*
* The subclass Others which will inherit all
* the properties of superclass Computer,
* namely
*        modelName
       screenSize
       processorSpeed
       ramSize
* Apart from these, it has its own attributes
* different from Apple class' attributes
*/
public class Others extends Computer{
   /*
   *
       Others laptop specific attributes(which are not
       present in Apple laptops)
       =============
       processorModel
       isHd
       ramType
       opeatingSystem
       color
   */
   private String processorModel;   // the brand model name as string
   private boolean isHd;           // boolean(if HD or not, true/false?)
   private String ramType;           // DDR or SDR
   private String operatingSystem;   // Windows, Linux, FreeDOS?
   private String color;           // Color of the laptop
   /*
   * Others constructor which takes the inherited attributes as well as
   * its own attributes to initialize an object of class "Others"
   * First 4 parameters are coming from the superclass "Computer",
   * while rest are Others specific parameters
   */
   private Others(String model, double size, double speed, int ram,
           String processor, boolean hd, String ramtype,
           String os, String color) {
      
       // invoke the superClass constructor (Computer's)
       super(model, size, speed, ram);
       // Assign rest of Others' specific attributes
       this.processorModel = processor;
       this.isHd = hd;
       this.ramType = ramtype;
       this.operatingSystem = os;
       this.color = color;
   }

   public static void main(String[] args) {
       /*
       * Create an Other-laptop object with all the necessary parameters,
       * name it ot, use ot to print the Other-laptop's specifications
       * in a formatted output
       *
       * 15.6-inch Dell i3552, 1.6GHz Processor, Intel Pentium N3700,
       * HD Laptop, 4 GB memory, DDR3L SDRAM, Windows 10, Black
       */

       Others ot = new Others("Dell i3552", 15.6, 1.66, 4,
                   "Pentium N3700", true, "DDR3L", "Windows 10", "Black");
       System.out.println("------- Details of a non-Apple laptop --------\n"
               + "Model: " + ot.modelName
               + "\nScreen: " + ot.screenSize + " inches"
               + "\nProcessor Speed: " + ot.processorSpeed + " GHz"
               + "\nProcessor Type: " + ot.processorModel
               + "\nHD(?): " + ot.isHd
               + "\nRAM : " + ot.ramSize + "GB " + ot.ramType
               + "\nOS: " + ot.operatingSystem
               + "\nColor: " + ot.color);
   }

}

Computer.java

Apple.java

Others.java

Execution screenshots:

Let me know if you have any further queries and I will be glad to assist. Thanks for asking :)


Related Solutions

Hello, Please write this program in java and include a lot of comments and please try...
Hello, Please write this program in java and include a lot of comments and please try to make it as simple/descriptive as possible since I am also learning how to code. The instructions the professor gave was: Create your own class Your own class can be anything you want Must have 3 instance variables 1 constructor variable → set the instance variables 1 method that does something useful in relation to the class Create a driver class that creates an...
This is a python program. Put comments explaining the code, please. Suppose you have been tasked...
This is a python program. Put comments explaining the code, please. Suppose you have been tasked with writing a Python program (using linked lists) to keep track of computer equipment. For each piece of equipment, we track its name, purchase date, purchase amount, and quantity on hand. Write a program that completes the following tasks: allow the user to add a piece of equipment to the front of the list; allow the user to update the quantity of a piece...
JAVA Please put detailed comments as well explaining your program. I'm in a beginning programming class,...
JAVA Please put detailed comments as well explaining your program. I'm in a beginning programming class, and so please use more basic techniques such as if else statements, switch operators, and for loops if needed. http://imgur.com/a/xx9Yc Pseudocode for the main method: Print the headings             Print the directions             Prompt for the month             If the month is an integer       (Hint: Use the Scanner class hasNextInt method.)                         Input the integer for the month                         Get the...
JAVA CODE BEGINNER , Please use comments to explain, please Repeat the calorie-counting program described in...
JAVA CODE BEGINNER , Please use comments to explain, please Repeat the calorie-counting program described in Programming Project 8 from Chapter 2. This time ask the user to input the string “M” if the user is a man and “W” if the user is a woman. Use only the male formula to calculate calories if “M” is entered and use only the female formula to calculate calories if “W” is entered. Output the number of chocolate bars to consume as...
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you...
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you move the first letter to the end of the word, and then spell the result backwards, you will get the original word: banana dresser grammar potato revive uneven assess Write a program that reads a word and determines whether it has this property. Continue reading and testing words until you encounter the word quit. Treat uppercase letters as lowercase letters.
write this program in java... don't forget to put comments. You are writing code for a...
write this program in java... don't forget to put comments. You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later. For example, if the user enters 9:21 the method should output 9:46 and if the user enters 10:52...
Please show solution and comments for this data structure using java.​ Implement a program in Java...
Please show solution and comments for this data structure using java.​ Implement a program in Java to convert an infix expression that includes (, ), +, -, *,     and / to postfix expression. For simplicity, your program will read from standard input (until the user enters the symbol “=”) an infix expression of single lower case and the operators +, -, /, *, and ( ), and output a postfix expression.
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
Methods – Compute Grade Please write a complete Java program, given the following information about (a...
Methods – Compute Grade Please write a complete Java program, given the following information about (a few lines of code in) main: projectAverage = getAverage(”Project”); // returns average of 2 grades testAverage = getAverage(”Test”); // returns average of 2 grades displayGrade(projectAverage, testAverage); // test are 70% & projects 30%
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT