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
Free brainliest!?! <3​
Sholpan [36]

Meee plzzzzz First!............

4 0
2 years ago
Read 2 more answers
1. Which of the following options will allow you to insert a quick table? (1 point) Insert ribbon > Shapes drop-down menu
emmasim [6.3K]
Quick tables are tables<span> that are stored in galleries as building blocks and can be reused and accessed at any time.</span>
The following option will allow you to insert a quick table:
Insert ribbon -> Table drop-down menu

Yous should click on the ribbon (tab) Insert and then from the Table drop-down in the Tables group, select Quick Tables.
5 0
3 years ago
Read 2 more answers
A characteristic often associated with entrepreneurship is
FromTheMoon [43]

Answer:

with small businesses

Explanation:

to make a lager profit

3 0
2 years ago
Why do software developers prefer to use high-level language to author programs?
Charra [1.4K]

Answer:

The answer to this question is given below in the explanation section

Explanation:

The correct answer to this question is: it used a more English-like syntax.

The software developer use high-level language to develop or author the program because it is more likely to English syntax and it would be easy for a software developer to author a program easily instead of using low level language and remembering ones and zeros.

Other options are not correct because:

It can be used on computers without microprocessors: Each computer has a microprocessor either you develop a program using high-level or low-level languages. Changes and modifications are easy in high-level language than in low-level languages. so, the option that prevents anyone from making changes to the software later is wrong.  However, high-level languages are less complicated in learning and in authoring the programs but it does not use zeros and ones, it uses English-like syntax. So, the last option is also wrong.  

4 0
2 years ago
Select the four tactics that cyber criminals use for stealing information from the list below.
Snowcat [4.5K]
Baiting clickjacking pharming spamming
6 0
2 years ago
Other questions:
  • 3. If the typical balance on Lucy's credit card is $750 and the interest rate (APR) on her credit card is 16%, how much in inter
    11·2 answers
  • Which of the following laptop features allows users to overcome keyboard size restrictions?
    11·1 answer
  • Arrange the steps below to outline what maia needs to do to accomplish this task.​
    9·1 answer
  • i set up an account and paid the yearly fee, now it's asking me to join. i've tried to log in and brainly isn't accepting my ema
    8·1 answer
  • Write Tic tac toe program in python for beginners pls
    10·1 answer
  • Which sensitivity level is not a default available in Outlook 2016?
    9·2 answers
  • Which is the best choice to explain why a human resource manager is so
    5·1 answer
  • The first real computer was an abacus?
    13·1 answer
  • Types of Hazards Mitigation Measures
    8·2 answers
  • what extension of nat allows several hundred workstations to access the internet with a single public internet address
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!