Question

In: Computer Science

write the following programs: Ram.java, Truck.java, LandVehicle.java and Vehicle.java. public class Ram extends Truck { public...

write the following programs: Ram.java, Truck.java, LandVehicle.java and Vehicle.java.

public class Ram extends Truck { public static void main(String[] args) {

    // your implementation
  }
  public Ram() {
    // your implementation

} }

public class Truck extends LandVehicle {
  public Truck() {
    // your implementation
  }
  public Truck(String s) {
    // your implementation

} }

public class LandVehicle extends Vehicle {
  public LandVehicle() {
    // your implementation
  }

}

public class Vehicle {
  public Vehicle() {
    // your implementation

Solutions

Expert Solution

You did not tell what should be implemented, so built a basic functional program for the above classes.

Ram.java

public class Ram extends Truck {
      public Ram(String s) {
       super(s);
       // TODO Auto-generated constructor stub
   }

   public static void main(String args[]){
          Vehicle v=new Vehicle();
          v.drive();
          LandVehicle lv = new LandVehicle();
          lv.LandDrive();
          lv.drive();
          Truck t = new Truck("Hello");
      
          Ram r = new Ram("Ram");
          r.drive();
          r.LandDrive();
      
}
}

Truck.java

public class Truck extends LandVehicle {

public Truck(String s) {
      System.out.println("Truck Driving " +s);
} }

LandVehicle.java

public class LandVehicle extends Vehicle {
public void LandDrive() {
      System.out.println("Land Driving");
    // your implementation
}

}

Vehicle.java

public class Vehicle {
public void drive() {
       System.out.println("Driving");
    // your implementation
}
}


Related Solutions

Consider the following code: public class Bay extends Lake { public void method1() { System.out.println("Bay 1");...
Consider the following code: public class Bay extends Lake { public void method1() { System.out.println("Bay 1"); super.method2(); } public void method2() { System.out.println("Bay 2"); } } //********************************* class Pond { public void method2() { System.out.println("Pond 2"); } } //************************** class Ocean extends Bay { public void method2() { System.out.println("Ocean 2"); } } //********************************* class Lake extends Pond { public void method3() { System.out.println("Lake 3"); method2(); } } //**************************** class Driver { public static void main(String[] args) { Object var4 =...
Write a class that extends the LeggedMammal class from the previous laboratory exercise.
C++ code on Visual Studio Code:Write a class that extends the LeggedMammal class from the previous laboratory exercise. The class will represent a Dog. Consider the breed, size and is registered. Initialize all properties of the parent class in the new constructor. This time, promote the use of accessors and mutators for the new properties. Instantiate a Dog object in the main function and be able to set the values of the properties of the Dog object using the mutators....
Write 2 short Java programs based on the description below. 1) Write a public Java class...
Write 2 short Java programs based on the description below. 1) Write a public Java class called WriteToFile that opens a file called words.dat which is empty. Your program should read a String array called words and write each word onto a new line in the file. Your method should include an appropriate throws clause and should be defined within a class called TextFileEditor. The string should contain the following words: {“the”, “quick”, “brown”, “fox”} 2) Write a public Java...
Write a java program that has a class named Octagon that extends the class Circ and...
Write a java program that has a class named Octagon that extends the class Circ and implements Comparable (compare the object's area) and Cloneable interfaces. Assume that all the 8 sides of the octagon are of equal size. Your class Octagon, therefore, must represent an octagon inscribed into a circle of a given radius (inherited from Circle) and not introduce any new class variables. Provide constructors for clas Octagon with no parameters and with 1 parameter radius. Create a method...
public class Flight extends java.lang.Object This class represents a single flight within the travel agency system....
public class Flight extends java.lang.Object This class represents a single flight within the travel agency system. Constructor Summary Constructors Constructor and Description Flight(java.lang.String airline, int flightNum, java.lang.String from, java.lang.String to, java.util.Calendar leavesAt, java.util.Calendar arrives, double price) Creates a new flight leg in the system. Method Summary All Methods Instance Methods Concrete Methods Modifier and Type Method and Description double getPrice() Retrieves the price of this flight. java.lang.String toString() Retrieves a formatted string summarizing this Flight. Methods inherited from class java.lang.Object...
How can the classes be modified to satisfy the comments: public class InvalidIntegerException extends Exception{    ...
How can the classes be modified to satisfy the comments: public class InvalidIntegerException extends Exception{     // Write a class for an InvalidIntegerException here     //Constructor that takes no arguments public InvalidIntegerException (){ super(); } //Constructor that takes a string message public InvalidIntegerException (String message){ super(message); } } import java.io.InputStream; import java.io.IOException; public class Parser { private InputStream in; public static final int CHAR_ZERO = (int) '0'; public Parser (InputStream in) { this.in = in; } // Complete the following...
Ram Corporation purchased a new truck on January 1, 2020 for $50,000.  The truck is expected to...
Ram Corporation purchased a new truck on January 1, 2020 for $50,000.  The truck is expected to last five years with a residual value of $10,000.  Using straight-line depreciation, show the effect on the income statement and balance sheet of this transaction over the next five years. Income statement 2020                 2021                 2022                 2023                 2024 Depreciation expense    $8000               $8000               $8000               $8000               $8000 Balance Sheet 2020                 2021                 2022                 2023                 2024 Equipment                    $                      $                      $                      $                      $ Less: accumulated   Depreciation               (                   )       (                 )       (                 )        (                 )        (                  ) Book value                    $                      $                      $                      $                      $                                                                                                                                                              Part II – Chapter 8                                     Company A                   Company B                   Company C Days sales in receivables            8.3 days                        39.9 days                      60.3 days Days sales in inventory              2.3...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and the current score of the PacmanGame. A score is a name and value that a valid name only contains the following characters: A to Z a to z 0 to 9 and must have a length greater than 0. The value is a integer that is equal to or greater than 0. Implement this for Assignment 1 Constructor Summary Constructors Constructor Description ScoreBoard() Creates...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and the current score of the PacmanGame. A score is a name and value that a valid name only contains the following characters: A to Z a to z 0 to 9 and must have a length greater than 0. The value is a integer that is equal to or greater than 0. Implement this for Assignment 1 Constructor Summary Constructors Constructor Description ScoreBoard() Creates...
public class ProductThread { static class ProductThreads extends Thread{ private int begin, end; int[] v1, v2;...
public class ProductThread { static class ProductThreads extends Thread{ private int begin, end; int[] v1, v2; long ris; public ProductThreads(String name, int [] v1, int [] v2, int begin, int end) { setName(name); this.v1 = v1; this.v2 = v2; this.begin = begin; this.end = end; this.ris = 0; } public void run() { System.out.println("Thread " + Thread.currentThread().getName() + "[" + begin + "," + end + "] started"); ris = 1; for(int i = begin; i <= end; i++) ris...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT