Question

In: Computer Science

Override the methods below (in SBox). The overridden methods should perform the actions mentioned below and...

Override the methods below (in SBox). The overridden methods should perform the actions mentioned below and it and must display the following message “Overridden method X”, where X is the method name.

a. setlength(int x ), to set the length

b. setWidth (int y ) to set the width

c. setHeight (int z) to set the height & d. displayCalculatedVolume( ) that calculates the volume and displays it.

Solutions

Expert Solution

/*Box is the base class and Sbox is the derived class*/

//importing packages

import java.util.*;
import java.lang.*;
import java.io.*;

class Box{
public void setLength(int x){
System.out.println("Length is "+x);
}
public void setWidth(int y){
System.out.println("Width is "+y);
}
public void setHeight(int z){
System.out.println("Height is "+z);
}
}
class Sbox extends Box{
int l,h,w;
public void setLength(int x){
System.out.println("Overidding method setLength..");
l = x;
}
public void setWidth(int y){
System.out.println("Overidding method setWidth..");
h = y;
}
public void setHeight(int z){
System.out.println("Overidding method setHeight..");
w = z;
}
public void displayCalculatedVolume(int x, int y, int z){
int vol;
setLength(x);
setWidth(y);
setHeight(z);
vol = l*h*w;
System.out.println("Volume is " + vol);
}
public static void main(String args[]){
Sbox obj = new Sbox();
obj.displayCalculatedVolume(2,3,6);
}
}

Output screenshot:

Note

  • This program is written in java.
  • A method is overridden when a derived class has the same method as the base class with the same signature (the parameters passed to the methods, in this case int x, int y, int z).
  • Here in the derived class we create an object 'obj' which calls the method displayCalculatedVolume(int x, int y, int z). This method calls the three methods setLength(int x), setWidth(int y) and setHeight(int z) to set the value to the class variables l,h,w. And calculate the volume of the box as well as dispay it.

Related Solutions

You have to write Statistics report of two pages using methods mentioned below- 0) Intro explains...
You have to write Statistics report of two pages using methods mentioned below- 0) Intro explains the value of the report and the goal (1) Show the prediction equation (2) Explain the range of usable values for the prediction (3)Explain the slope (4) Determine whether the slope is significant (5) Specify the alpha used (6) Correlation explained (7)Standard error for the model explained (8) Justifies the model was appropriate (9) Calculates the prediction requested (10) Discusses the error of the...
Identify the weak actions of the salesperson below and what the salesperson should have done: Customer...
Identify the weak actions of the salesperson below and what the salesperson should have done: Customer (on the phone): Good Morning! I am Howard from Tank's Transport. I am following up on the order we had placed for 40 truck tires. Sales person: Yes, how can I help you? Customer: Well we wanted to know if we would definitely get delivery by next Friday? Sales person: I had mentioned to Mr. Harris, your General Manager, that we would try our...
what four actions do cells have the ability to perform?
what four actions do cells have the ability to perform?
Part A: (Chapter 8) Make the following updates to the original code below: Override the toString()...
Part A: (Chapter 8) Make the following updates to the original code below: Override the toString() method and equals() method inside your class [2 points] Create a Copy Constructor in your class [2 point] Create a static field in your class called counter. It should increment every time an object is created. [1 point] Create a static method that displays the counter value. Also call this method at the end of your main method. [1 point] Use the "this" reference...
Other than those mentioned in the chapter, what actions might a company take to reduce risk?...
Other than those mentioned in the chapter, what actions might a company take to reduce risk? (Business Finance Page 194,Chapter 6.) Typing please,thank you.
Choose and explain one of the debt financing methods mentioned in the textbook. What are the...
Choose and explain one of the debt financing methods mentioned in the textbook. What are the strengths and weaknesses of the method that you've chosen, and in what situations does it work best? Give an example of a company that uses this strategy. Be sure to support your ideas and arguments with evidence and details.
Write a program to perform the following actions: the language is Java – Open an output...
Write a program to perform the following actions: the language is Java – Open an output file named “Assign14Numbers.txt” – Using a do-while loop, prompt the user for and input a count of the number of random integers to produce, make sure the value is between 35 and 150, inclusive. – After obtaining a good count, use a for-loop to generate the random integers in the range 0 ... 99, inclusive, and output each to the file as it is...
(Java 8th Person edition) Exercise 13.9, p. 536 (Enable Circle comparable). Override the following methods: compareTo...
(Java 8th Person edition) Exercise 13.9, p. 536 (Enable Circle comparable). Override the following methods: compareTo (interface Comparable), toString (class GeometricObject) and equals (class Object).Create an array of comparable circles, sort them and display the result of a sorting procedure. Then create one more circle, which is equal to one of the existing circles and demonstrate the work of the method equals(). I added the code that the question references, but I'm not even quite too sure what it's asking...
In Java please. Prompt the user for two string inputs. Perform the following actions on these...
In Java please. Prompt the user for two string inputs. Perform the following actions on these inputs, and print the result of each action: Part I: Concatenate the two strings into one. Compare the two strings and check whether they are the same (ignore the case). Look up the method equalsIgnoreCase() from Java API Convert all the characters in a string to uppercase Look up the method toUpperCase() from Java API Part II: Replace all the 'd' characters with ‘e'...
Describe two useful methods to “perform quantitative analysis
Describe two useful methods to “perform quantitative analysis
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT