Given the following 2 definitions for Computer and Notebook: public class Comput
ID: 3870724 • Letter: G
Question
Given the following 2 definitions for Computer and Notebook:
public class Computer {
private String manufacturer;
private String processor;
private int ramSize;
private int diskSize;
private double processorSpeed;
public Computer(String manuf, String proc, int ram, int disk, double prcSpeed){
manufacturer = manuf;
processor = proc;
ramSize = ram;
diskSize = disk;
processorSpeed = prcSpeed;
}
public int getRamSize(){
return ramSize;
}
public int getDiskSize(){
return diskSize;
}
public double getProcessorSpeed(){
return processorSpeed;
}
public String toString(){
return "manufacturer: " + manufacturer + " " +
" processor: " + processor + " "+
" ramSize: " + ramSize + " " +
" diskSize: " + diskSize + " " +
" processorSpeed: " + processorSpeed;
}
}
public class Notebook extends Computer {
private double screenSize;
private double weight;
public Notebook( String manuf, String proc, int ram, int disk,
double prcSpeed, double ScrnSz, double wt){
super(manuf, proc, ram, disk, prcSpeed);
screenSize = ScrnSz;
weight = wt;
}
public double getScreenSize(){
return screenSize;
}
public double getWeight(){
return weight;
}
}
And:
Computer myComputer = new Computer("Acme", "Intel", 2, 160, 2.4);
Computer workComputer = new Notebook("DellGate", "AMD", 4, 240, 1.8, 15.0, 7.5);
(1) Which line of code doesn't compile?
a) workComputer.getWeight();
b) workComputer.getRamSize();
c) workComputer.getProcessorSpeed();
d) workComputer.toString();
Explanation / Answer
Answer: workComputer.getWeight();
Source Code:
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Computer {
private String manufacturer;
private String processor;
private int ramSize;
private int diskSize;
private double processorSpeed;
public Computer(String manuf, String proc, int ram, int disk, double prcSpeed){
manufacturer = manuf;
processor = proc;
ramSize = ram;
diskSize = disk;
processorSpeed = prcSpeed;
}
public int getRamSize(){
return ramSize;
}
public int getDiskSize(){
return diskSize;
}
public double getProcessorSpeed(){
return processorSpeed;
}
public String toString(){
return "manufacturer: " + manufacturer + " " +
" processor: " + processor + " "+
" ramSize: " + ramSize + " " +
" diskSize: " + diskSize + " " +
" processorSpeed: " + processorSpeed;
}
}
class Notebook extends Computer {
private double screenSize;
private double weight;
public Notebook( String manuf, String proc, int ram, int disk,
double prcSpeed, double ScrnSz, double wt){
super(manuf, proc, ram, disk, prcSpeed);
screenSize = ScrnSz;
weight = wt;
}
public double getScreenSize(){
return screenSize;
}
public double getWeight(){
return weight;
}
}
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Computer myComputer = new Computer("Acme", "Intel", 2, 160, 2.4);
Computer workComputer = new Notebook("DellGate", "AMD", 4, 240, 1.8, 15.0, 7.5);
workComputer.getWeight();
}
}
Output:
Resolving Error:
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Computer {
private String manufacturer;
private String processor;
private int ramSize;
private int diskSize;
private double processorSpeed;
public Computer(String manuf, String proc, int ram, int disk, double prcSpeed){
manufacturer = manuf;
processor = proc;
ramSize = ram;
diskSize = disk;
processorSpeed = prcSpeed;
}
public int getRamSize(){
return ramSize;
}
public int getDiskSize(){
return diskSize;
}
public double getProcessorSpeed(){
return processorSpeed;
}
public String toString(){
return "manufacturer: " + manufacturer + " " +
" processor: " + processor + " "+
" ramSize: " + ramSize + " " +
" diskSize: " + diskSize + " " +
" processorSpeed: " + processorSpeed;
}
}
class Notebook extends Computer {
private double screenSize;
private double weight;
public Notebook( String manuf, String proc, int ram, int disk,
double prcSpeed, double ScrnSz, double wt){
super(manuf, proc, ram, disk, prcSpeed);
screenSize = ScrnSz;
weight = wt;
}
public double getScreenSize(){
return screenSize;
}
public double getWeight(){
return weight;
}
}
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
//Computer myComputer = new Computer("Acme", "Intel", 2, 160, 2.4);
Notebook workComputer = new Notebook("DellGate", "AMD", 4, 240, 1.8, 15.0, 7.5);
workComputer.getWeight();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.