Question

In: Computer Science

Create a sub class of the class Box and call it SBox. The SBox class has...

Create a sub class of the class Box and call it SBox. The SBox class has inherited the list of variables and methods from Box & has its own members too.

a. It has a variable color having a String data type.

b. This class also has a method called SetColor( ) which read the color from the user (Use JOptionPane), set the color to the value given by the user and display it.

Solutions

Expert Solution

import javax.swing.*;

public class Box

{
   private String name;

protected String getname()

{
   return this.name;

}
   protected void setname()

{
  this.name=JOptionPane.showInputDialog(null,"Please enter box name");

}
protected void displayName (JFrame jFrame)

{

JOptionPane.showMessageDialog(jFrame,"Box name is" + this.name);

}
public static void main(String[] args)
{
   SBox sBox= new SBox();

sBox.setName();

sBox.setcolor();

JFrame frame = new JFrame("SBox");

frame.setSize(200,200);

frame.setLocationRelativeTo(null);

frame.setVisible(false);

sBox.displayName(frame);

sBox.displayColor(frame);

  }
class SBox extends Box

{
private String color;

public void setColor()

{
   this.color = JOptionPane.showInputDialog(null,"Please enter box color:");

}
   public void displayColor(JFrame jFrame)

{
   JOptionPane.showMessageDialog(jFrame, "Color of box named" + this.getName() + "is" + this.color);

}
}


Related Solutions

Question1: Consider the below description of the class Box. 1. Create a class and call it...
Question1: Consider the below description of the class Box. 1. Create a class and call it Box. Box has the following methods & variables a. Variable for length, height, width & volume, b. setlength(int x ) method to set the length, c. setWidth (int y ) method to set the width, d. setHeight (int z ) method to set the height & e. displayCalculatedVolume( ) method that calculates the volume and displays it. (Hint: volume = length*width*height)
Write a program to create a bank account and to process transactions. Call this class bankAccount...
Write a program to create a bank account and to process transactions. Call this class bankAccount A bank account can only be given an initial balance when it is instantiated. By default, a new bank account should have a balance of 0. A bank account should have a public get method, but no public set method. A bank account should have a process method with a double parameter to perform deposits and withdrawals. A negative parameter represents a withdrawal. It...
The following code is for a class named Box. The class Box includes a constructor method...
The following code is for a class named Box. The class Box includes a constructor method Box, and a method getVolume(). For your assignment you are to develop a java class named MatchBox. Your class MatchBox must extend the class Box and in addition to the attributes width, height, and depth that are defined in the class Box, MatchBox must add a new attribute weight. The getVolume method must both report the values of width, height, depth, and weight, but...
Using eclipse IDE, create a java project and call it applets. Create a package and call...
Using eclipse IDE, create a java project and call it applets. Create a package and call it multimedia. Download an image and save it in package folder. In the package, create a java applet where you load the image. Use the drawImage() method to display the image, scaled to different sizes. Create animation in Java using the image. In the same package folder, download a sound. Include the sound in your applets and make it repeated while the applet executes....
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
create a speaker box with a volume of 14400 cubic inches. The box will be used...
create a speaker box with a volume of 14400 cubic inches. The box will be used for speakers of various sizes. The speaker box must have a square base and minimal surface area ( prior to cutting holes for the speakers ). Find the box’s dimensions. Your must construct a diagram [ V = LWH ]
Design a Java Animal class (assuming in Animal.java file) and a sub class of Animal named...
Design a Java Animal class (assuming in Animal.java file) and a sub class of Animal named Cat (assuming in Cat.java file). The Animal class has the following protected instance variables: boolean vegetarian, String eatings, int numOfLegs and the following public instance methods: constructor without parameters: initialize all of the instance variables to some default values constructor with parameters: initialize all of the instance variables to the arguments SetAnimal: assign arguments to all of the instance variables Three “Get” methods which...
Create a class called FibGenerator with 3 methods: public int nthFib(int n). This method should call...
Create a class called FibGenerator with 3 methods: public int nthFib(int n). This method should call computeFibRecurse(n). private int computeFibRecurse(int n), which should recurse (that is, call itself) unless n is 1 or 2. If n is 1 or 2, the method should return 1. A main method that prints “STARTING”, then constructs a FibGenerator generator and then calls nthFib(), passing in interesting values. To look into this problem, you’re going to use software to analyze software. Add an instance...
Create a class named TestLease whose main() method declares four Lease objects. Call a getData() method...
Create a class named TestLease whose main() method declares four Lease objects. Call a getData() method three times. Within the method, prompt a user for values for each field for a Lease, and return a Lease object to the main() method where it is assigned to one of main()’s Lease objects. Do not prompt the user for values for the fourth Lease object, but let it continue to hold the default values. Then, in main(), pass one of the Lease...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults to 1. It has read-only properties that calculate the Perimeter and the Area of the rectangle. It has properties for both length and width. The set accessors should verify that length and width are each floating-point numbers greater than 0.0 and less than 20.0. Write an app to test class Rectangle. this is c sharp program please type the whole program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT