Suppose that the following two classes have been declared public class Car f public void m1) System.out.println("car 1"; public void m2) System.out.println("car 2"); public String toString) f return "vroom"; public class Truck extends Car public void m1) t System.out.println("truck 1"); public void m2) t super.m1); public String toString) t return super.toString) super.toString ); Write a class MonsterTruck whose methods have the behavior below. Don't just print/return the output; whenever possible, use inheritance to reuse behavior from the superclass Methog Output/Return monster 1 truck1 car 1 m2 toString "monster vroomvroom'" Type your solution here:

Answers

Answer 1

Answer: provided in the explanation section

Explanation:

// code to copy

Car.java

public class Car {

 

  public void m1()

  {

  System.out.println("car 1");

}

 

  public void m2() {

      System.out.println("car 2");

}

 

  public String toString()

  {

  return "vroom";

}

 

}

Truck.java

public class Truck extends Car{

 

  public void m1()

  {

  System.out.println("truck 1");

  }

 

  public void m2()

  {

  super.m1();

  }

 

  public String toString()

  {

      return super.toString() + super.toString();

  }

}

MonsterTruck​​​​​​​.java

public class MonsterTruck extends Truck

{

  public void m1() {

System.out.println("monster 1");

}

 

public void m2() {

super.m1();

super.m2();

}

 

public String toString() {

return "monster " + super.toString();

}

public static void main(String[] args) {

  MonsterTruck mt=new MonsterTruck();

  mt.m1();

  mt.m2();

  System.out.println(mt);

}

}

cheers i hope this helped !!!


Related Questions

An introduction to object-oriented programming.
Write a GUI program named EggsInteractiveGUI that allows a user to input the number of eggs produced in a month by each of five chickens. Sum the eggs, then display the total in dozens and eggs. For example, a total of 127 eggs is 10 dozen and 7 eggs.

Answers

Answer:

The csharp program is given below.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace WindowsFormsApplication1

{

   public partial class Form1 : Form

   {

       public Form1()

       {

           InitializeComponent();

      }

       private void button6_Click(object sender, EventArgs e)

       {

           int total = (Convert.ToInt32(textBox1.Text) +  Convert.ToInt32(textBox2.Text) + Convert.ToInt32(textBox3.Text) + Convert.ToInt32(textBox4.Text) + Convert.ToInt32(textBox5.Text));

           int dozen = total / 12;

           int eggs = total % 12;

           textBox6.Text = dozen.ToString();

           textBox7.Text = eggs.ToString();

       }

       private void button7_Click(object sender, EventArgs e)

       {

           textBox1.Text = "";

           textBox2.Text = "";

           textBox3.Text = "";

           textBox4.Text = "";

           textBox5.Text = "";

           textBox6.Text = "";

           textBox7.Text = "";

       }

        private void button8_Click(object sender, EventArgs e)

       {

           Close();

       }

    }

}

Explanation:

1. The integer variables are declared for total eggs, number of dozens and number of eggs.

2. The input of each text box is converted into integer by using the Convert.ToInt32() method on the value of that particular text box.

3. All the inputs are added and the sum is assigned to variable, total.

4. The number of dozens are obtained by dividing total by 12 and assigning the value to the variable, dozen.

5. The number of extra eggs are obtained by taking the modulus of total and 12 and the value is assigned to the variable, eggs.

6. The integer values in the variables, dozen and eggs, are converted into string using the ToString() function with that particular value.

dozen.ToString();

eggs.ToString();

7. The text boxes are assigned the respective values of dozens and number of eggs.

textBox6.Text = dozen.ToString();

textBox7.Text = eggs.ToString();

8. Two additional buttons, clear and exit, are also added.

9. The clear button erases the contents of all the text boxes. The Text property of each textbox is set to “” thereby clearing all the text fields.

10. The exit button closes the application using Close() function.

11. The program is made in visual studio and the output is attached.

Other Questions
What might happen to the organisms in the food web below if the number of phytoplankton and vegetation drastically decreased? A paper manufacturer packages twelve reams of paper in a boxin three stacks of four reams. A ream of paper weighs 5 pounds and has dimensions of 8.5 inches by 11 inches by 2 inches. What is the volume of the current-sized box? a0 cubic inches If the market price of an orange increases from $0.80 to $1.05, then consumer surplus. Name First orange Second orange Third orange Allison $2 $1.5 $0.75 Bob $1.5 $1 $0.6 Charisse $0.75 $0.25 $0 Group of answer choices increases by $0.75 decreases by $0.95. decreases by $0.75 decreases by $1.00 Which reason would most effectively refute the counterclaim?Counterclaim: In addition to writing acclaimed lyrics, Bob Dylan has written both prose and poetry.I have read Dylans book of poetry, Tarantula, and his memoir, Chronicles: Volume One, and think that both books are worthy of the Nobel Prize in Literature. I just dont think that Dylans song lyrics should be awarded in the same category as his books.It is true that Bob Dylan has published traditional poetry and prose. However, neither of the books was very good, and neither won prestigious awards. If the Nobel Prize in Literature considered all writers of at least two mediocre books, the award would mean nothing.It is true that Bob Dylan has published traditional poetry and prose. However, one book of poetry and one memoir would not qualify him for the prize. The prize was awarded based on his songwriting, which does not qualify as literature. Two very large parallel sheets a distance d apart have their centers directly opposite each other. The sheets carry equal but opposite uniform surface charge densities. A point charge that is placed near the middle of the sheets a distance d/2 from each of them feels an electrical force F due to the sheets. If this charge is now moved closer to one of the sheets so that it is a distance d/4 from that sheet, what force will feel A portrait of Mrs. Elizabeth Freake and Baby Mary. A woman holds her baby on her lap in a chair. Who is the artist of the painting above? a. Poussin b. Christopher Wren c. Antoine Le Nain d. The artist is unknown. Please select the best answer from the choices provided A B C Sum of the ages of a father and the son is 40 years. If father's age is 3 times that of his son, then father's age is ________ * 2 points 35 40 30 45 Why didn't the fungus evolve to be resistant to bacteria's antibiotics? giving brainliest to first answer!!Determine the area of the composite figure to the nearest whole number.A)9 ft2B)11 ft2C)13 ft2D)17 ft2 Is the following shape a rectangle The base of a rectangular prism has an area of 24 square millimeters. The volume of the prism is 144 cubic millimeters. The shape is a cube. What is the height of the prism? A blow dryer transfers thermal energy mainly byA. conductionB. convectionC. radiationD. specific heat III.The analogies below are word problems that consist of two wordpairs. Look at the first pair and decide how the two words relate toeach other. Then select one of the words below so the second pair ofwords has the same relationship.1. CORRUPT. MORALSA) talented : skall B) rude intelligence C) fortunate money D) ruthless: mercy What are the x- and y-intercepts of the graph of 5x 4y = 20? x-int: 5, y-int: 4 x-int: 5, y-int: 4 x-int: 4, y-int: 5 x-int: 4, y-int: 5 porrr favoooooorrr! :(( the are of one of the bases of the figure shown above is about 21.2 cm sq. What is the surface area, in cm sq, of the figure? round your answer to the nearest tenth 9,7,7,7 cm PLZZ HELPP Why is it important to simplify rational expressions before multiplying or dividing? How do you determine that a rational expression is in simplest form? Compare the process to addition and subtraction. 1. The precious metals needed to make computer chips, graphic cards, and transistors are found in only a small population of countries. What economic implications does this have for the countries that have these metals to mine? .WHAT ARE THE MERITS AND DEMERITS OF MNC A client is a devout jew.what are two things that the nurse aide can do to make him comfortable?