1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Julli [10]
2 years ago
9

In Java: Write a class called Shelf that contains instance data that repre-sents the length, breadth, and capacity of the shelf.

Also include a boolean variable called occupied as instance data that repre-sents whether the shelf is occupied or not. Define the Shelf con-structor to accept and initialize the height, width, and capacity of the shelf. Each newly created Shelf is vacant (the constructor should initialize occupied to false). Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the shelf. Create a driver class called ShelfCheck, whose main method instantiates and updates several Shelf objects.
Computers and Technology
1 answer:
disa [49]2 years ago
5 0

Answer:see explanation

Explanation:

Hello, the solution is the following:

in a file named Shelf.java :

public class Shelf{

   int length;

   int breadth;

   int capacity;

   boolean occupied;

   Shelf(int length,int breadth, int capacity){

       this.length = length;

       this.breadth = breadth;

       this.capacity = capacity;

       this.occupied = false;

   }

   

   //set methods

   public void setLength(int length){

       this.length = length;

   }

   public void setBreadth(int breadth){

       this.breadth = breadth;

   }

   public void setCapacity(int capacity){

       this.capacity = capacity;

   }

   public void setOccupied(boolean occupied){

       this.occupied = occupied;

   }

   

   //get methods

   public int getLength(){

       return this.length;

   }

   public int getBreadth(){

       return this.breadth;

   }

   public int getCapacity(){

       return this.capacity;

   }

   public boolean getOccupied(){

       return this.occupied;

   }

   

   //tostring method

   

   public String toString(){//overriding the toString() method  

 return "Shelf: \n"+" length: "+Integer.toString(this.length)+" breadth: "+Integer.toString(this.breadth)+" capacity: "+Integer.toString(this.capacity)+" occupied: "+Boolean.toString(this.occupied);

}  

}

in another file named ShelfCheck.java

public class ShelfCheck {

 public static void main(String[] args) {

   Shelf s1=new Shelf(100,150,300);

   Shelf s2=new Shelf(200,200,234);  

   Shelf s3=new Shelf(300,222,543);  

   Shelf s4=new Shelf(400,434,654);

   System.out.println(s1);

   System.out.println(s2);

   System.out.println(s3);

   System.out.println(s4);

   s4.setLength(5);

   System.out.println(s4);

   s2.setBreadth(2);

   System.out.println(s2);

   s3.setCapacity(1);

   System.out.println(s3);

   s1.setOccupied(true);

   System.out.println(s1);

 }

}

OUTPUT:

Shelf:

length: 100 breadth: 150 capacity: 300 occupied: false

Shelf:

length: 200 breadth: 200 capacity: 234 occupied: false

Shelf:

length: 300 breadth: 222 capacity: 543 occupied: false

Shelf:

length: 400 breadth: 434 capacity: 654 occupied: false

Shelf:

length: 5 breadth: 434 capacity: 654 occupied: false

Shelf:

length: 200 breadth: 2 capacity: 234 occupied: false

Shelf:

length: 300 breadth: 222 capacity: 1 occupied: false

Shelf:

length: 100 breadth: 150 capacity: 300 occupied: true

You might be interested in
In a two-sided tag, a(n) ____ tag indicates the content's end.
alexira [117]

Answer:

A closing tag

Explanation:

A tag in HTML is the core building block that marks the presence of an element. If the element has text or another element within it, it is marked using a two-sided tag and in which case, the opening tag indicates the content’s beginning and a closing tag indicates the end of the content

7 0
3 years ago
Read 2 more answers
Robyn needs to ensure that a command she frequently uses is added to the Quick Access toolbar. This command is not found in the
Semenov [28]

Answer: Access Quick Access commands using the More button

Explanation:

In order for Robyn to ensure that a command she frequently uses is added to the Quick Access toolbar, then she needs to Access Quick Access commands using the More button.

This can be done by clicking on Customize Quick Access Toolbar. Then, Robyn will then click More Commands then he'll click on file tab in the Choose commands from the list. The command will then be chosen and then click on Ok and it'll be added.

7 0
2 years ago
PlZZZZZZZ help will give Brainliest
dalvyx [7]

Answer:

Phone

Explanation:

3 0
2 years ago
Read 2 more answers
What type of activities are performed with the help of the software used in hospitals?
faust18 [17]

Answer:

Xrays, Ultrasounds, managing patient records, communicating with colleagues, etc.

7 0
2 years ago
Read 2 more answers
The new tag in HTML 5 means that it explanation or pronunciation of characters for Asian typography O sets a container for an ex
Eddi Din [679]

Answer:

yes very correctExplanation:

5 0
2 years ago
Other questions:
  • What is the rationale behind the development of an operating system in computing?
    15·1 answer
  • The following slide was created as part of a presentation that trains new employees how to use the scheduling and calendar softw
    14·2 answers
  • Develop a list of privacy protection features that should be present if a website is serious about protecting privacy. Then, vis
    8·1 answer
  • 1. The global economy involves trading between people from different _____
    8·1 answer
  • When you open as many links as you want, and still stay in the same browser window instead of cluttering your screen with multip
    5·1 answer
  • Where do you place the logical test argument in an JF function formula?
    5·2 answers
  • in java how do i Write a Java program that takes ten numbers as input to calculate and print the average of the numbers.
    11·1 answer
  • 3.3 Code Practice: Question 1
    15·1 answer
  • WILL MARK BRAINLIEST FOR ANYONES ANSWER!
    12·1 answer
  • The network backbone
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!