Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java and please the do the first picture methods and run it with the test codes at the bottom thank you! public static void testShapeList()

java and please the do the first picture methods and run it with the test codes at the bottom thank you!

image text in transcribedimage text in transcribed

public static void testShapeList() { // ToDo: uncomment the following tests Point p25 = new Point(2,5); Point p48 = new Point(4,8); Shape r00 = new Rectangle(); Shape c25 = new Circle(9, p25); ShapeList l = new ShapeList(); displayResults(l.size() == 0, "test contructor with size");

l.add(r00); displayResults(l.size() == 1, "test add with size"); String resultString = l.toString(); String expectedString = r00.toString() + " "; System.out.println("result:" + resultString); System.out.println("expected:" + expectedString); displayResults(resultString.equals(expectedString), "test add with toString");

l.add(c25); displayResults(l.size() == 2, "test add with size"); resultString = l.toString(); expectedString = r00.toString() + " " + c25.toString() + " "; System.out.println("result:" + resultString); System.out.println("expected:" + expectedString); displayResults(resultString.equals(expectedString), "test add with toString"); // ToDo: add test to see if your ShapeList will expand when needed l.removeFront(); displayResults(l.size() == 0, "test remove with size"); resultString = l.toString(); expectedString = ""; System.out.println("result:" + resultString); System.out.println("expected:" + expectedString); displayResults(resultString.equals(expectedString), "test remove with toString"); }

public class Shape List private static final int DEFAULT_SIZE = 2; private Shape [] elements; private int count; public ShapeList() { // TODO: initialize the fields elements = new Shape [DEFAULT_SIZE] ; count = 0; // elements should be initialized as an empty // array that holds DEFAULT_SIZE shapes } * Purpose: returns the number of elements in list Parameters: none * Returns: int - the number of elements public int size() { return count; Purpose: adds Shape s to back of this list Parameters: Shape * Returns: nothing - S public void add (Shape s) { // TODO } * Purpose: returns a String reprensentation of the elements in this list separated by newlines * Parameters: none * Returns: String - the representation * public String toString() { String s = "List contents:"; for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

Repeat Problem 11.9 for an m-step backward predictor.

Answered: 1 week ago

Question

The Power of Public Speaking Clarifying the

Answered: 1 week ago