JavaAs1
JavaAs1
Source code
class Vehicle {
String make;
String model;
int year;
String fuelType;
twofold fuelEfficiency;
twofold maxSpeed;
public Vehicle(String make, String model, int year, String fuelType, twofold fuelEfficiency, twofold
maxSpeed) {
this.make = make;
this.model = model;
this.year = year;
this.fuelType = fuelType;
this.fuelEfficiency = fuelEfficiency;
this.maxSpeed = maxSpeed;
System.out.println("Vehicle Data: " + year + " " + make + " " + model);
System.out.println("Fuel Type: " + fuelType);
twofold cargoCapacity;
public Truck(String make, String model, int year, String fuelType, twofold fuelEfficiency, twofold
maxSpeed, twofold cargoCapacity) {
this.cargoCapacity = cargoCapacity;
super.displayInfo();
boolean isElectric;
public Car(String make, String model, int year, String fuelType, twofold fuelEfficiency, twofold
maxSpeed, boolean isElectric) {
this.isElectric = isElectric;
super.displayInfo();
System.out.println("Is Electric: " + (isElectric ? "Indeed" : "No"));
boolean hasSidecar;
public Motorcycle(String make, String model, int year, String fuelType, twofold fuelEfficiency,
twofold maxSpeed, boolean hasSidecar) {
this.hasSidecar = hasSidecar;
super.displayInfo();
Vehicle = new Car("Tesla", "Model S", 2023, "Electric", 120, 155, valid);
Bike cruiser = new Motorcycle("Harley-Davidson", "Road 750", 2021, "Gas", 50, 110,
misleading);
System.out.println("Truck Information:");
truck.displayInfo();
System.out.println("Car Information:");
car.displayInfo();
System.out.println("Motorcycle Information:");
motorcycle.displayInfo();
2. Compose a Java program to make a connection point Flyable with a strategy called fly_obj().
Make three classes Rocket, Plane, and Helicopter that carry out the Flyable point of interaction.
Carry out the fly_obj() strategy for every one of the three classes.
interface Flyable {
3. Compose a Java program to make a technique that peruses a record and tosses a special case in
the event that the document isn't found.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
attempt {
readFile(filePath);
} get (FileNotFoundException e) {
if (!file.exists()) {
while (scanner.hasNextLine()) {
System.out.println(line);
scanner.close();
}
4.Write a Java program that peruses a document and tosses a special case assuming that the
record is vacant.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
attempt {
checkFileForContent(fileLocation);
System.out.println(ex.getMessage());
ex.printStackTrace();
bufferedReader = invalid;
attempt {
if (currentLine == invalid) {
} System.out.println("File content:");
System.out.println(currentLine);
currentLine = bufferedReader.readLine();
} at last {
bufferedReader.close();
super(message);