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
Help me
mestny [16]

Answer:

  1. True
  2. False
  3. False
  4. True
  5. False

Explanation:

mark me as brainlyest

6 0
3 years ago
Read the section, "Junior Year." Why would someone chose to complete an apprenticeship after high school? How many occupations c
Tamiku [17]

An apprenticeship prepares you for a career through a structured program of on-the-job learning with classroom instruction, while you work and earn a salary. The programs can last from one to six years and you can choose careers in areas such as telecommunications, health care, computing, business support and the arts. The most common apprenticeships are in construction and manufacturing. If you like to work with your hands and your mind, you might want to consider an apprenticeship after high school. More than 850 occupations can be learned on the job through an apprenticeship.

7 0
3 years ago
Read 2 more answers
Why would a person who handles electronic components wear a grounded wrist strap
Otrada [13]
Normally, wrist straps like this are used to prevent static electric discharge, which can ruin electric components.<span />
5 0
3 years ago
When opening a file in Windows, the creation of ____ helps bridge the gap between the characteristics of physical devices and di
ololo11 [35]

Answer:

an electronic computer folder

4 0
4 years ago
SUWIDHA stands for .​
Anettt [7]
SUWIDHA stands for Single User-friendly Window Disposal & Help-line for Applicants.

Hope it helps
5 0
3 years ago
Other questions:
  • How many times does the following loop execute? double d; Random generator = new Random(); double x = generator.nextDouble() * 1
    14·1 answer
  • What does this mean?
    7·2 answers
  • "The OSI model has seven layers and the DoD has four. At which layer does SMTP works in both models"?
    15·1 answer
  • Create a program to calculate the wage. Assume people are paid double time for hours over 60 a week. Therefore they get paid for
    10·1 answer
  • Having one password for all accounts is an easy way to remember passwords, but it will expose you to what risk?
    15·1 answer
  • If a computer truncatesall numbers to two decimal places, compute the error forthe following: 23.345+222.34911)0.12)0.01413)0.14
    15·1 answer
  • How many different Roblox games were played in 2018​
    9·2 answers
  • Write a program that requests the user input a word, then prints every other letter of the word starting with the first letter.
    5·1 answer
  • Write a function writel that will write the length of a side of a square. If only one argument is passed to the function, it is
    10·1 answer
  • How does our behavior change when we know we're being watched?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!