Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is the object class:
- package com.Suarez;
- /* object class
- */
- public class Box
- {
- private int W;
- private int L;
- private int H;
- public Box()//default constructor
- {
- W=1;
- L=1;
- H=1;
- }
- public Box(int W1, int L1,int H1) // lets you set the value for the W & L & H of the box
- {
- W=W1;
- L=L1;
- H=H1;
- }
- public void setW(int W1)//mutator for W
- {
- W = W1;
- }
- public void setL(int L1)//mutator for L
- {
- L = L1;
- }
- public void setH(int H1) // mutator for H
- {
- H = H1;
- }
- public int getW()//assessor for W
- {
- return W;
- }
- public int getL()//assessor for L
- {
- return L;
- }
- public int getH() // assessor for H
- {
- return H;
- }
- public void translateSize(int dW,int dL, int dH)
- {
- W = W + dW;
- L = L + dL;
- H = H + dH;
- }
- public int calculateArea()
- {
- int area = W * L;
- return area;
- }
- public int calculateVolume()
- {
- int volume = W * L * H;
- return volume;
- }
- public String boxToString()
- {
- String box = ("The width of the box is " + W + ", the length is " + L +", and the height is " + H);
- return box;
- }
- }
- Here is the client class:
- package com.Suarez;
- public class ClientBox {
- public static void main(String [] args)
- {
- Box b1 = new Box(2, 4, 3);
- Box b2 = new Box(5, 2, 12);
- //the code below will output the information for box b1
- System.out.println("Box b1 has the following dimensions and values");
- System.out.println(b1.boxToString());
- System.out.println("The box has an area of " + b1.calculateArea());
- System.out.println("The box has a volume of " + b1.calculateVolume());
- // this is so that the two boxes will be seperated
- System.out.println();
- // the code below will output the information for box b2
- System.out.println("Box b2 has the following dimensions and values");
- System.out.println(b2.boxToString());
- System.out.println("The box has an area of " + b2.calculateArea());
- System.out.println("The box has a volume of " + b2.calculateVolume());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement