The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 314 Weeks Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
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:
Â
Â
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:
----------- Â ----------- 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