Write in-line comments that are necessary. Don't write a comment for what is obvious from the code. There are 2 different programs. (Subject is JAVA PROGRAMMING)   First Program: // Main.java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the Carrier: "); String carrier = input.nextLine(); System.out.print("Enter the Type: "); String type = input.nextLine();

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write in-line comments that are necessary. Don't write a comment for what is obvious from the code. There are 2 different programs. (Subject is JAVA PROGRAMMING)

 

First Program:

// Main.java

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter the Carrier: ");

String carrier = input.nextLine();

System.out.print("Enter the Type: ");

String type = input.nextLine();

System.out.print("Enter the Speed: ");

double speed = Double.parseDouble(input.nextLine());

System.out.print("Enter the Memory: ");

double memory = Double.parseDouble(input.nextLine());

System.out.print("Enter the Number Of Apps: ");

int numApps = Integer.parseInt(input.nextLine());

CellPhone p1 = new CellPhone(carrier, type, speed, memory, numApps);

System.out.println("\nCarrier = " + p1.getCarrier());

System.out.println("Type of phone = " + p1.getType());

System.out.println("Speed of phone = " + p1.getSpeed() + " Ghz");

System.out.println("Memory = " + p1.getMemory() + " Gb");

System.out.println("Number of Apps = " + p1.getNumApps());

}

}

//Cellphone.java

public class CellPhone {

private String carrier, type;

private double speed, memory;

private int numApps;

/*

* parameterized constructor

*

* @param carrier

* @param type

* @param speed

* @param memory

* @param numApps

*/

public CellPhone(String carrier, String type, double speed, double memory, int numApps) {

this.carrier = carrier;

this.type = type;

this.speed = speed;

this.memory = memory;

this.numApps = numApps;

}

/*

* default constructor

*/

public CellPhone() {

}

/*

* @return the carrier

*/

public String getCarrier() {

return carrier;

}

/*

* @param carrier the carrier to set

*/

public void setCarrier(String carrier) {

this.carrier = carrier;

}

/*

* @return the type

*/

public String getType() {

return type;

}

/*

* @param type the type to set

*/

public void setType(String type) {

this.type = type;

}

/*

* @return the speed

*/

public double getSpeed() {

return speed;

}

/*

* @param speed the speed to set

*/

public void setSpeed(double speed) {

this.speed = speed;

}

/*

* @return the memory

*/

public double getMemory() {

return memory;

}

/*

* @param memory the memory to set

*/

public void setMemory(double memory) {

this.memory = memory;

}

/*

* @return the numApps

*/

public int getNumApps() {

return numApps;

}

/*

* @param numApps the numApps to set

*/

public void setNumApps(int numApps) {

this.numApps = numApps;

}

}

Main.java is the client program and CellPhone.java is the class file.

 

 

Second program:

// Main.java

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Vehicle car = new Car(9.4);

Vehicle truck = new Truck(14.1);

Vehicle hybridcar = new HybridCar(3.8);

Vehicle motorcycle = new Motorcycle(6.3);

double litre;

System.out.print("Enter amount of gas in litre: ");

Scanner sc = new Scanner(System.in);

litre = sc.nextDouble();

System.out.println("On " + litre + "L of gas the vehicle can drive: \n");

System.out.println("Car= " + car.getDistance(litre) + "KM");

System.out.println("Truck= " + truck.getDistance(litre) + "KM");

System.out.println("Hybrid Car= " + hybridcar.getDistance(litre) + "KM");

System.out.println("Motorcycle= " + motorcycle.getDistance(litre) + "KM");

sc.close();

}

}

// Car.java

public class Car extends Vehicle {

public Car(double mileage) {

super(mileage);

}

}

// HybridCar.java

public class HybridCar extends Vehicle {

public HybridCar(double mileage) {

super(mileage);

}

}

// Motorcycle.java

public class Motorcycle extends Vehicle {

public Motorcycle(double mileage) {

super(mileage);

}

}

// Truck.java

public class Truck extends Vehicle {

public Truck(double mileage) {

super(mileage);

}

}

// Vehicle.java

public class Vehicle {

private double mileage;

public Vehicle(double mileage) {

this.mileage = mileage;

}

public double getDistance(double litre) {

return (litre * 100) / mileage;

}

}

Main.java is the client program. Class files are Car.java, HybridCar.java, Motorcycle.java, Truck.java, and Vehicle.java.

Expert Solution
steps

Step by step

Solved in 7 steps with 11 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education