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

public class Mammal extends SeaCreature { public void method1() { System.out.println("warm-blooded"); } } public class SeaCreature...
public class Mammal extends SeaCreature { public void method1() { System.out.println("warm-blooded"); } } public class SeaCreature { public void method1() { System.out.println("creature 1"); } public void method2() { System.out.println("creature 2"); } public String toString() { return "ocean-dwelling"; } } public class Whale extends Mammal { public void method1() { System.out.println("spout"); } public String toString() { return "BIG!"; } } public class Squid extends SeaCreature { public void method2() { System.out.println("tentacles"); } public String toString() { return "squid"; } } What...
You coded the following class: public class N extends String, Integer { } When you compile,...
You coded the following class: public class N extends String, Integer { } When you compile, you get the following message: N.java:1: ‘{‘ expected public class N extends String, Integer                                                ^ 1 error Explain what the problem is and how to fix it.
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 =...
Consider the following classes: public class Clock extends Bear { public void method3() { System.out.println("Clock 3");...
Consider the following classes: public class Clock extends Bear { public void method3() { System.out.println("Clock 3"); } } public class Lamp extends Can { public void method1() { System.out.println("Lamp 1"); } public void method3() { System.out.println("Lamp 3"); } } public class Bear extends Can { public void method1() { System.out.println("Bear 1"); } public void method3() { System.out.println("Bear 3"); super.method3(); } } public class Can { public void method2() { System.out.println("Can 2"); method3(); } public void method3() { System.out.println("Can 3"); }...
What would be the result of each of the following programs? 1 public class RecursionInJava1{   public...
What would be the result of each of the following programs? 1 public class RecursionInJava1{   public static void main(String args[]) {        System.out.println(guess(9));    } Public static int guess(int num){          if (num == 1)                   return 0;          else                   return (guess(num-2)-num); } } 2 public class RecursionInJava2{   public static void main(String args[]) {    System.out.println(sum(10));     }      public static int sum(int number){        //base case   if(number == 7){   return 0;   }   return sum(number-1)+number    } }
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...
The questions in this assessment use the following. class R { ... } class A extends...
The questions in this assessment use the following. class R { ... } class A extends R { ... } abstract class B extends R { ... } final class C extends R { ...} class D extends A { ... } class E extends B { ... } class F extends B { ... } // none of the classes implement a toString() method [0] Draw a class hierarchy for the classes defined above. [1] No or Yes: class...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT