SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 314 Weeks Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 16 Dec 2017 My Price 10.00

modify the GridWriter class by adding additional collection

Could you help me with one more task?

 

GridWriter Class: You will modify the GridWriter class by adding additional collection style functionality. The GridWriter class should get two new methods:

 

  • public int size() should return the number of GridItems stored in the GridWriter
  • public GridItem get(int index) should return the stored GridItems by index.

 

Consider the following code. The first line creates a GridWriter object. Then two items are added to the GridWriter. The index of the items will be 0, and 1. Notice how the for loop uses the size and get methods to print out the areas of the two items

 

GridWriter gw = new GridWriter(40, 50);

          

gw.add(new MyCircle(10, 10, 9));

gw.add(new MyRectangle(40, 0, 10, 10));

          

for (int i = 0; i < gw.size(); i++) {

        System.out.println(gw.get(i).getArea());

}        

 

Once you have these two methods working you should add exception logic to the get method. The following code should cause your GridWriter to thow an IndexOutOfBoundsException.

 

GridWriter gw = new GridWriter(40, 50);

          

gw.add(new MyCircle(10, 10, 9));

gw.add(new MyRectangle(40, 0, 10, 10));

 

GridItem i = gw.get(2);

 

Although the array inside the Gridwriter has a capacity of 4, it only stores two GridItems. â2â is not a valid index. Add a throws statement to your get method that will thow an IndexOutOfBoundsException for any invalid index.

Attachments:

Answers

(5)
Status NEW Posted 16 Dec 2017 07:12 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)