Junit test provided, won't take you more than 15 mins.
Be sure you can pass the test.
---------------------------------------------------------
For this problem you will need to write the Square superclass and 2 subclasses of Square. The name of each of the classes you will write and the work they must do is as follows:
Square
Define an instance-based field of type double named length. Make certain the field has proper access protections. You should also define a getter & setter for this field.
Define a constructor which has a single double parameter: use the value of that parameter to set the initial value of length.
Define the method public double getArea() method so that it returns the area of the instance (e.g., length *length).
Cube
This must be a subclass of Square.
Define a constructor which has a single double parameter: use the value of that parameter to set the initial value of length (remember that Cube is-a Square).
Define a method public double getVolume() so that it returns the volume of the instance (e.g., length *length * length).
If any work is required (and this may or may not be required), make sure the getter and setter for lengthare usable.
Box
This must be a subclass of Square .
Define a field of type double named height. Make certain the field has proper access protections. You should also define a getter & setter for this field.
Define a constructor which has two double parameters: use the first parameter to set the length of the basic Square and the second parameter to set the instance's height.
The area of a box would depend on the cross-section examined. Update it's getArea() method so that it returns Double.NaN.
Define the method public double getVolume() so that it returns the volume of the instance (e.g., length *length * height).
If any work is required (and this may or may not be required), make sure the getter and setter for lengthare usable.
-------------------------------------------------
Junit test
package edu.buffalo.cse116;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
* @author Matthew Hertz
*/
public class GeometryTest {
@Test
public void testSquareGetArea() {
Square square = new Square(3);
Square notCircle = new Square(14.0);
Square regular = new Square(0.5);
assertEquals("Did not construct or getArea correctly", 9,
square.getArea(), 0.0);
assertEquals("Did not construct or getArea correctly", 196,
notCircle.getArea(), 0.0);
assertEquals("Did not construct or getArea correctly", 0.25,
regular.getArea(), 0.0);
square.setLength(5);
assertEquals("Did not setLength or getArea correctly", 25,
square.getArea(), 0.0);
}
@Test
public void testSquareGetLength() {
Square square = new Square(1);
assertEquals("Did not construct or getLength correctly", 1.0,
square.getLength(), 0.0);
Square notSquare = new Square(10.0);
assertEquals("Did not construct or getLength correctly", 10.0,
notSquare.getLength(), 0.0);
}
@Test
public void testSquareSetLength() {
Square circ = new Square(1);
Square notSquare = new Square(10.0);
circ.setLength(34);
assertEquals("Did not set or getLength correctly", 34.0,
circ.getLength(), 0.0);
notSquare.setLength(0.00001);
assertEquals("Did not set or getLength correctly", 0.00001,
notSquare.getLength(), 0.0);
}
@Test
public void testCubeGetArea() {
Cube cube = new Cube(3);
Square notSquare = new Cube(-14.0);
assertEquals("Did not construct or getArea correctly", 3 * 3,
cube.getArea(), 0.0);
assertEquals("Did not construct or getArea correctly", -14 * -14,
notSquare.getArea(), 0.0);
}
@Test
public void testCubeGetLength() {
Cube cube = new Cube(7);
assertEquals("Did not construct or getLength correctly", 7.0,
cube.getLength(), 0.0);
Cube notSquare = new Cube(0.1);
assertEquals("Did not construct or getLength correctly", 0.1,
notSquare.getLength(), 0.0);
}
@Test
public void testCubeGetVolume() {
Cube square = new Cube(3);
Square notSquare = new Cube(23.0);
assertEquals("Did not construct or getVolume correctly", 3 * 3 * 3,
square.getVolume(), 0.0);
assertEquals("Did not construct or getVolume correctly", 23 * 23 *
23, ((Cube)notSquare).getVolume(), 0.0);
notSquare.setLength(0.02);
assertEquals("Did not setLength or getVolume correctly", 0.02 *
0.02 * 0.02, ((Cube)notSquare).getVolume(), 0.0);
}
@Test
public void testCubeSetLength() {
Square square = new Cube(1);
Cube notSquare = new Cube(10.0);
notSquare.setLength(17);
assertEquals("Did not set or getLength correctly", 17.0,
notSquare.getLength(), 0.0);
square.setLength(10000);
assertEquals("Did not set or getLength correctly", 10000,
square.getLength(), 0.0);
}
@Test
public void testBoxGetArea() {
Box square = new Box(6, 10);
Square notSquare = new Box(15.0, 32);
assertEquals("Did not construct or getArea correctly", Double.NaN,
square.getArea(), 0.0);
assertEquals("Did not construct or getArea correctly", Double.NaN,
notSquare.getArea(), 0.0);
}
@Test
public void testBoxGetLength() {
Square square = new Box(7, 0.01);
assertEquals("Did not construct or getLength correctly", 7.0,
square.getLength(), 0.0);
Box notSquare = new Box(0.1, -8);
assertEquals("Did not construct or getLength correctly", 0.1,
notSquare.getLength(), 0.0);
}
@Test
public void testBoxGetVolume() {
Box square = new Box(3, 89);
Square notSquare = new Box(23.0, 0.1);
assertEquals("Did not construct or getVolume correctly", 9 * 89,
square.getVolume(), 0.0);
assertEquals("Did not construct or getVolume correctly", 23 * 23 *
0.1, ((Box)notSquare).getVolume(), 0.0);
notSquare.setLength(0.02);
assertEquals("Did not setLength or getVolume correctly", 0.0004 *
0.1, ((Box)notSquare).getVolume(), 0.0);
square.setHeight(1);
assertEquals("Did not setHeight or getVolume correctly", 9,
square.getVolume(), 0.0);
}
@Test
public void testBoxSetLength() {
Square square = new Box(1, 0.1);
Box notSquare = new Box(10.0, 0.2);
notSquare.setLength(17);
assertEquals("Did not set or getLength correctly", 17.0,
notSquare.getLength(), 0.0);
square.setLength(10000);
assertEquals("Did not set or getLength correctly", 10000,
square.getLength(), 0.0);
}
@Test
public void testBoxSetHeight() {
Square square = new Box(1, 0.1);
Box notSquare = new Box(10.0, 0.2);
notSquare.setHeight(17);
assertEquals("Did not set or getLength correctly", 17.0,
notSquare.getHeight(), 0.0);
((Box)square).setHeight(10000);
assertEquals("Did not set or getLength correctly", 10000,
((Box)square).getHeight(), 0.0);
}
}
package edu.buffalo.cse116;
public class Square {
private double length;
/**
* @param length
*/
public Square(double length) {
this.length = length;
}
/**
* @return the length
*/
public double getLength() {
return length;
}
/**
* @param length
* the length to set
*/
public void setLength(double length) {
this.length = length;
}
public double getArea() {
return getLength() * getLength();
}
}
package edu.buffalo.cse116;
public class Cube extends Square {
/**
* @param length
*/
public Cube(double length) {
super(length);
// TODO Auto-generated constructor stub
}
public double getVolume() {
return getLength() * getLength() * getLength();
}
}
package edu.buffalo.cse116;
public class Box extends Square {
private double height;
public Box(double length, double height) {
super(length);
// TODO Auto-generated constructor stub
this.height = height;
}
/**
* @return the height
*/
public double getHeight() {
return height;
}
/**
* @param height
* the height to set
*/
public void setHeight(double height) {
this.height = height;
}
@Override
public double getArea() {
// TODO Auto-generated method stub
return Double.NaN;
}
public double getVolume() {
return getLength() * getLength() * getHeight();
}
}
package edu.buffalo.cse116;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
* @author Matthew Hertz
*/
public class GeometryTest {
@Test
public void testSquareGetArea() {
Square square = new Square(3);
Square notCircle = new Square(14.0);
Square regular = new Square(0.5);
assertEquals("Did not construct or getArea correctly", 9,
square.getArea(), 0.0);
assertEquals("Did not construct or getArea correctly", 196,
notCircle.getArea(), 0.0);
assertEquals("Did not construct or getArea correctly", 0.25,
regular.getArea(), 0.0);
square.setLength(5);
assertEquals("Did not setLength or getArea correctly", 25,
square.getArea(), 0.0);
}
@Test
public void testSquareGetLength() {
Square square = new Square(1);
assertEquals("Did not construct or getLength correctly", 1.0,
square.getLength(), 0.0);
Square notSquare = new Square(10.0);
assertEquals("Did not construct or getLength correctly", 10.0,
notSquare.getLength(), 0.0);
}
@Test
public void testSquareSetLength() {
Square circ = new Square(1);
Square notSquare = new Square(10.0);
circ.setLength(34);
assertEquals("Did not set or getLength correctly", 34.0,
circ.getLength(), 0.0);
notSquare.setLength(0.00001);
assertEquals("Did not set or getLength correctly", 0.00001,
notSquare.getLength(), 0.0);
}
@Test
public void testCubeGetArea() {
Cube cube = new Cube(3);
Square notSquare = new Cube(-14.0);
assertEquals("Did not construct or getArea correctly", 3 * 3,
cube.getArea(), 0.0);
assertEquals("Did not construct or getArea correctly", -14 * -14,
notSquare.getArea(), 0.0);
}
@Test
public void testCubeGetLength() {
Cube cube = new Cube(7);
assertEquals("Did not construct or getLength correctly", 7.0,
cube.getLength(), 0.0);
Cube notSquare = new Cube(0.1);
assertEquals("Did not construct or getLength correctly", 0.1,
notSquare.getLength(), 0.0);
}
@Test
public void testCubeGetVolume() {
Cube square = new Cube(3);
Square notSquare = new Cube(23.0);
assertEquals("Did not construct or getVolume correctly", 3 * 3 * 3,
square.getVolume(), 0.0);
assertEquals("Did not construct or getVolume correctly", 23 * 23 * 23,
((Cube) notSquare).getVolume(), 0.0);
notSquare.setLength(0.02);
assertEquals("Did not setLength or getVolume correctly",
0.02 * 0.02 * 0.02, ((Cube) notSquare).getVolume(), 0.0);
}
@Test
public void testCubeSetLength() {
Square square = new Cube(1);
Cube notSquare = new Cube(10.0);
notSquare.setLength(17);
assertEquals("Did not set or getLength correctly", 17.0,
notSquare.getLength(), 0.0);
square.setLength(10000);
assertEquals("Did not set or getLength correctly", 10000,
square.getLength(), 0.0);
}
@Test
public void testBoxGetArea() {
Box square = new Box(6, 10);
Square notSquare = new Box(15.0, 32);
assertEquals("Did not construct or getArea correctly", Double.NaN,
square.getArea(), 0.0);
assertEquals("Did not construct or getArea correctly", Double.NaN,
notSquare.getArea(), 0.0);
}
@Test
public void testBoxGetLength() {
Square square = new Box(7, 0.01);
assertEquals("Did not construct or getLength correctly", 7.0,
square.getLength(), 0.0);
Box notSquare = new Box(0.1, -8);
assertEquals("Did not construct or getLength correctly", 0.1,
notSquare.getLength(), 0.0);
}
@Test
public void testBoxGetVolume() {
Box square = new Box(3, 89);
Square notSquare = new Box(23.0, 0.1);
assertEquals("Did not construct or getVolume correctly", 9 * 89,
square.getVolume(), 0.0);
assertEquals("Did not construct or getVolume correctly", 23 * 23 * 0.1,
((Box) notSquare).getVolume(), 0.0);
notSquare.setLength(0.02);
assertEquals("Did not setLength or getVolume correctly", 0.0004 * 0.1,
((Box) notSquare).getVolume(), 0.0);
square.setHeight(1);
assertEquals("Did not setHeight or getVolume correctly", 9,
square.getVolume(), 0.0);
}
@Test
public void testBoxSetLength() {
Square square = new Box(1, 0.1);
Box notSquare = new Box(10.0, 0.2);
notSquare.setLength(17);
assertEquals("Did not set or getLength correctly", 17.0,
notSquare.getLength(), 0.0);
square.setLength(10000);
assertEquals("Did not set or getLength correctly", 10000,
square.getLength(), 0.0);
}
@Test
public void testBoxSetHeight() {
Square square = new Box(1, 0.1);
Box notSquare = new Box(10.0, 0.2);
notSquare.setHeight(17);
assertEquals("Did not set or getLength correctly", 17.0,
notSquare.getHeight(), 0.0);
((Box) square).setHeight(10000);
assertEquals("Did not set or getLength correctly", 10000,
((Box) square).getHeight(), 0.0);
}
}
OUTPUT:
![กู้เ JUnit Finished after 0.031 seconds Runs: 12/12 Errors: 0 Failures: 0 eubuffalo.csel16.GeometryTest [Runner. JUnit 4] (0.](http://img.homeworklib.com/questions/fde11b20-22cd-11eb-a6d5-5730c6b4e07b.png?x-oss-process=image/resize,w_560)
Junit test provided, won't take you more than 15 mins. Be sure you can pass the...
This wont take you more than 15 mins. Comple the two method and besure to test with Junit test that provided below. toArray() -- this method returns a newly allocated array containing the elements in the multiset. The array this method returns must only contain the elements in the multiset and not any nulls or other values that are stored in the backing store, but are not in the multiset. fromArray(E[] arr) -- this method updates the multiset so that...
(Need to complete the methods and pass a Junit test i can email them to you.) public class Triangle implements Comparable { /** * Stores the number of objects instantiated from the {@code Triangle} class */ private static int numTriangles; /** * The shortest side of the triangle */ private final double a; /** * The side of medium length of the triangle */ private final double b;...
this is for java programming Please Use Comments I am not 100% sure if my code needs work, this code is for the geometric if you feel like you need to edit it please do :) Problem Description: Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometricObject class for finding the larger (in area) of two GeometricObject objects. Draw the UML and implement the new GeometricObject class and its two subclasses...
Java Program 1. Write a class that reads in a group of test scores (positive integers from 1 to 100) from the keyboard. The main method of the class calls a few other methods to calculate the average of all the scores as well as the highest and lowest score. The number of scores is undetermined but there will be no more than 50. A negative value is used to end the input loop. import java.util.Scanner; public class GradeStat {...
For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...
Lab Exercise 05.1 Interest Rate PLEASE USE JAVA Compound interest is the way that you can turn a little bit of money into a lot of money, if you have enough time. We have seen this calculation in a previous lab. This exercise will rewrite the program but will define a class named interestRate which will contain several separate methods. These methods will be incorporated into the class definition so that they can be tested by a main test program...
In Problem Set 7 you designed and implemented a Message class. This time, let's design and implement a Mailbox class in a file named Mailbox java. Do the following with this class • You may use the Message class from PS 7. You will have to add new features to the Message class from PS 7 as you work through this problem. You are welcome to start with my sample solution if you wish • Suppose there are multiple mail...
This is assignment and code from this site but it will not
compile....can you help?
home / study / engineering / computer science / computer science
questions and answers / c++ this assignment requires several
classes which interact with each other. two class aggregations
...
Question: C++ This assignment requires several classes
which interact with each other. Two class aggregatio...
(1 bookmark)
C++
This assignment requires several classes which interact with
each other. Two class aggregations are formed. The program...
URGENT
I have 3 hours for Submit this Homework so you can share
yout codes with me in 150mins
Preliminary Notes: You have 4 hours to submit your solution. No late submission is accepted. Do not leave your submission to the last minute. You are not allowed to copy any code from anywhere. Your code will be checked by a software for similarity. Implement the code on your own and never share it with someone else. A test code is...
Java Project For this assignment, you will write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: delete the addfirst, addlast, and add(index) methods and instead include a single add method...