Question

In: Computer Science

//JAVA //basic please for learning programming 2. Thank you. Write the Class Variables Class Box is...

//JAVA
//basic please for learning programming 2. Thank you.

Write the Class Variables
Class Box is to have the following private data members:

  • height of type double
  • width of type double
  • length of type double

Write the following Overridden Method
Class Box is to have an overridden equals() method that does the following:​​​​

  • tests to see if the parameter represents an object (null test)
  • tests to see if the parameter object is of the same class type as the calling object (class test)
  • determines if the calling object and the parameter object store identical data values for the corresponding data members (variable to variable test)

Write the Get and Get Methods
Class Box is to have standard get/set methods for each data member
Write the following Auxiliary Method
Class Box is to have an auxiliary method getVolume( ). The method is to have an access of public and return a value of type double. The method is to do the following:

  • calculate and return the volume of the box
  • volume is calculated by multiplying the length of the box by the width of the box by the height of the box

Write the Constructors
Class Box is to have two constructors with the following specifications:

  • a no-arg constructor that initializes each double data member to zero
  • a constructor that takes three parameters, each representing one of the class data members. the arguments are to be listed in the order of (height, width, length)

Class: Box
Write the class header
Write the following Overridden Method
Class Box is to have an overridden toString() method that does the following:

  • displays the following information in the format presented:

Height: display height of the object
Width: display the width of the object
Length: display the length of the object
Write the following application class: BoxApp.

Class BoxApp is to do the following:

  • create an object of type Box named smallBox that has a height of 3, a width of 4 and a length of 5;
  • create an object of type Box named mediumBox that has a height of 6, a width of 7 and a length of 8;
  • create an object of type Box named unknownBox that has a height of 0, a width of 0 and a length of 0;
  • test to see if smallBox equals unknown box. If they are equal, display the word true. If they are not equal, display the word false.
  • output the following information for smallBox

Height: the value of the height property
Width: the value of the width property
Length: the value of the length property

Solutions

Expert Solution

Box.java

public class Box {

   private double height;
   private double width;
   private double length;

   public Box() {
       height = 0;
       width=0;
       length=0;

   }

   public Box(double height, double width, double length) {
       super();
       this.height = height;
       this.width = width;
       this.length = length;
   }

   @Override
   public boolean equals(Object obj) {

       if (this == obj) {
           return true;
       }
       if (this == null || obj.getClass() != this.getClass()) {
           return false;
       }
       Box box = (Box) obj;

       return box.getHeight() == this.getHeight() && box.getLength() == this.getLength()
               && box.getWidth() == this.getWidth();
   }

   // Auxiliary Method
   public double getVolume() {
       return height * width * length;
   }

   // getters and setters

   public double getHeight() {
       return height;
   }

   public void setHeight(double height) {
       this.height = height;
   }

   public double getWidth() {
       return width;
   }

   public void setWidth(double width) {
       this.width = width;
   }

   public double getLength() {
       return length;
   }

   public void setLength(double length) {
       this.length = length;
   }

   @Override
   public String toString() {
       return "height:" + height +"\n"+ "width:" + width +"\n"+ "length:" + length ;
   }
  

BoxApp.java

public class BoxApp {
  
   public static void main(String[] args) {
       Box smallBox= new Box(3,4,5);
       Box mediumBox=new Box(60, 7, 8);
       Box unknownBox=new Box(0,0,0);
      
       System.out.println(smallBox.equals(unknownBox));
       System.out.println();
       System.out.println("The following information for smallBox");
       System.out.println(smallBox.toString());
   }

}


  

}


Related Solutions

Using C++ programming. Thank you. Money class has the following member variables and functions. -member variable...
Using C++ programming. Thank you. Money class has the following member variables and functions. -member variable : dollar, cent -member function : setMoney(int dollar, int cent), printMoney(), operator overloading(+) Program the Money class so that the following function can be performed. int main(){ Money a, b, c; A.setMoney(10, 60); B.setMoney(20, 70; (a+b).printMoney(); c = a + b; c.printMoney(); }
Java Programming Using the class below, please ), write a static method called parse that parses...
Java Programming Using the class below, please ), write a static method called parse that parses a String for balanced parentheses. we seek only to determine that the symbol ‘{‘ is balanced with ‘}’. parse accepts a single String parameter and returns an int. If parse returns a minus 1, then there are no errors, otherwise, parse should return the position within the String where an error occurred. For example parse(“{3 + {4/2} }”)   would return -1 parse(“{ { 4*X}”)...
In Java please. Thank you! Recursion For this assignment you are going to write six different...
In Java please. Thank you! Recursion For this assignment you are going to write six different methods. Each method is to be written recursively. Any method that is written iteratively will not receive any credit, even if it is correct and produces the same results or output. You will be given a starter file. You are not allowed to change the signatures of any of the given methods. You are not allowed to add any methods to your solutions. Write...
in Java please For this assignment you are to write a class that supports the addition...
in Java please For this assignment you are to write a class that supports the addition of extra long integers, by using linked-lists. Longer than what is supported by Java's built-in data type, called long. Your program will take in two strings, consisting of only digits, covert each of them to a linked-list that represents an integer version on that string. Then it will create a third linked-list that represents the sum of both of the linked lists. Lastly, it...
Postfix Evaluation (JAVA PROGRAMMING) Write class PostfixEva1uator that evaluates a postfix expression such as 6 2...
Postfix Evaluation (JAVA PROGRAMMING) Write class PostfixEva1uator that evaluates a postfix expression such as 6 2 + 5 * 8 4 / - The program should read a postfix expression consisting of single digits and operators into a StringBuilder, The program should read the expression and evaluate it (assume it's valid). The algorithm to evaluate a postfix expression is shown below. Use +, -, *, /, and ^. ^ is the exponent. Append a right parenthesis ') ' to the...
[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter...
[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter five floating point values from the keyboard (warning: you are not allowed to use arrays or sorting methods in this assignment - will result in zero credit if done!). Have the program display the five floating point values along with the minimum and maximum values, and average of the five values that were entered. Your program should be similar to (have outputted values be...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
You need to make an AngryBear class.(In java) The AngryBear class must have 2 instance variables....
You need to make an AngryBear class.(In java) The AngryBear class must have 2 instance variables. The first instance variable will store the days the bear has been awake. The second instance variable will store the number of teeth for the bear. The AngryBear class will have 1 constructor that takes in values for days awake and number of teeth. The AngryBear class will have one method isAngry(); An AngryBear is angry if it has been awake for more than...
For My Programming Lab - Java: Write a Temperature class that will hold a temperature in...
For My Programming Lab - Java: Write a Temperature class that will hold a temperature in Fahrenheit and provide methods to get the temperature in Fahrenheit, Celsius, and Kelvin. The class should have the following field: • ftemp: a double that holds a Fahrenheit temperature. The class should have the following methods : • Constructor : The constructor accepts a Fahrenheit temperature (as a double ) and stores it in the ftemp field. • setFahrenheit: The set Fahrenheit method accepts...
Question: Java Programming. ** Modify Current Program. Current Program class Account{       //instance variables   ...
Question: Java Programming. ** Modify Current Program. Current Program class Account{       //instance variables    private long accountNumber;    private String firstName;    private String lastName;    private double balance;       //constructor    public Account(long accountNumber, String firstName, String lastName, double balance) {        this.accountNumber = accountNumber;        this.firstName = firstName;        this.lastName = lastName;        this.balance = balance;    }    //all getters and setters    public long getAccountNumber() {        return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT