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]
3 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]3 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
Send this as a Python file. Note: this is an example where you have the original file, and are writing to a temp file with the n
Nonamiya [84]

Answer:

you have to include insted the file the instructions...

Explanation:

that is what you need to do (if that is what you are asking)

6 0
4 years ago
Read 2 more answers
When doing a complex presentation, which of the following would be the best tool to begin designing your presentation?
Dafna1 [17]
An outline can be a best tool to begin describes a presentation....
4 0
4 years ago
Read 2 more answers
Please help me asapppp!​
I am Lyosha [343]

Answer:

1.  Formula is A2 : A9 = COUNT( A2: A9 ) = 8

2. Formula is SUM( A2: A9 ) = 36

3. Formula is B2 : B9 = COUNT( B2: B9) = 8

4. Formula is  MAX( C2: C9) = 5

5. Formula is MIN( C4: C8) = 3

6. Formula is SUM( C5 - C6) = 0

7. Formula is AVERAGE( C2: C9) = 4

Explanation: Have a nice day!✌️

6 0
3 years ago
Many programming languages require a ____ to create executable files.
Nadya [2.5K]
Most languages require a compiler. This is because machine code consists of only 0s and 1s, which is executable. All other languages have to be translated into machine language by a compiler.
4 0
4 years ago
A ____ is a prewritten formula that is built into excel.
kondor19780726 [428]
A function is a prewritten formula that is built into excel.
3 0
4 years ago
Other questions:
  • An Ethernet network, all data travels across the network and between computers in which form or unit?
    12·1 answer
  • The actual database of Active Directory shared resources is stored on one or more computers designated as:
    6·1 answer
  • Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 the output is
    5·1 answer
  • Write a program that Read first n lines of file
    8·1 answer
  • Please can someone help me answer this question.
    11·1 answer
  • Why is information broken down into packets
    15·1 answer
  • After several rounds of sessions and reviews, you finally have a list of confirmed requirements from a client in the music indus
    8·1 answer
  • There are many advantages and some disadvantages to using social media. Explain at least one of the advantages to
    5·1 answer
  • Core to resource management system is the _________that coordinates the server hardware.
    8·1 answer
  • The agency that started ARPANET was looking for
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!