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
The following is true about SPAM ________.
aev [14]

Answer:

a, c, and d.

Explanation:

Let's examine these options:

a -> Spamming can be used to obtain information about the individuals. Those emails can contain links that try to reveal your sensitive information. They can also contain viruses directly like in the some attached folder. Another usage of spamming is just to advertise some products.

c -> Spam emails are not something you requested for. They are just sent to email addresses in huge amounts.

d -> As mentioned earlier, they can be used to obtain personal information like password, credit card information.

8 0
3 years ago
General equation: y = (89 / 27) - z * x + a / (a % 2) (recall: a is an integer; the 89 and 27 constants in the equation should b
liraira [26]

Answer: Here is an Incomplete question submitted

Explanation:

6 0
3 years ago
Annabella was giving a presentation to a group of 20 real estate agents on
podryga [215]

Anticipate questions.

3 0
3 years ago
Read 2 more answers
Suppose we have a linearly separable dataset, and we divide the data into training and validation sets. Will a perceptron learne
Sauron [17]

Answer:

Theoretically Yes

Explanation:

The data given is linearly separable. So, the subset of the data will also be linearly separable. And it will pass for all training dataset. However, you should definitely never expect such thing In any real-life problem because the data is noisy, for a bazilion of reasons, so no model is guaranteed to perform perfectly.

3 0
3 years ago
Linux distributions overview? information​
disa [49]

Answer:

Debian

Arch Linux

Ubuntu

Fedora

Manjaro

Linux Mint

Elementary OS

openSUSE

Explanation:

6 0
3 years ago
Other questions:
  • The EPA requires the use of precise forms called ?
    14·1 answer
  • Choosing firm goals for your business
    7·2 answers
  • Which of these can be considered data?<br> A:facts<br> B:information<br> C:belief<br> D:all of these
    9·1 answer
  • Page orientation can be either landscape or _____.
    13·1 answer
  • After a robbery, what is the purpose of conducting a neighborhood canvass?
    9·1 answer
  • Wide area networks are defined by their ability to
    14·2 answers
  • ¿Es especial que mi cumpleaños sea el día de San Valentín?<br><br> si o no
    11·2 answers
  • what are the benefits of VolP? select all that apply. A:cheaper printings B:clearer calls C: faster download D: increased effici
    11·2 answers
  • To check spelling errors in a document, the Word application uses the _____ to determine appropriate spelling.
    7·2 answers
  • Synapse is not working and is crashing every time you attach it. What should you do?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!