Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This unit features some elegant solutions to programming challenges, and many of them share one common traitthey all handle multiple objects with ease. Forget for

This unit features some elegant solutions to programming challenges, and many of them share one common traitthey all handle multiple objects with ease. Forget for the moment about some of the complexity involved. The formulas may seem strange, but dont worry. At this stage of programming, youre not expected to generate such things on your own; very few new programmers can. Instead, stop to consider the ways this units programs embrace the computers true assets. Machines dont mind doing the same thing over and over again; they never get bored. Theyre also capable of handling massive amounts of data in an impeccably organized manner. One of your challenges as a programmer is to communicate, through code, in an efficient way that plays to the computers strengths. Consider the Piano program, for example. You could have placed the keys using 12 different constructors. Youd probably never ask yourself, What number should I multiply the width of the keys by, in order to generalize these horizontal key positions? After all, it would take you longer to perform 12 calculations than it would to just line up the keys and move them around until they looked right (especially if you misplaced your calculator). Computers dont typically play around until they solve a problem. They need a more precise method. Besides, those 12 lines of key constructor code are a lot bulkier than the lines it takes to write a loop that does the same thing. Even worse, if you had to build a real piano, it would require 88 keys, and the 88 lines of code it would require to place them in a brute force way is much longer and more repetitive than a carefully crafted loop with a thoughtful class definition. Loops arent the only elegant, computer-centric solutions presented in this unit. Consider the arrays from Chapter 5, which defined all of the important characteristics of the piano keys in two simple lines. In Chapter 6, the computer could instantly identify all of the objects on the screen and place them into one big list. Even better, once those objects were in a list, you could apply a for-each loop to invoke a method for each of them. Think, for a moment, about how powerful that is! Without even knowing how many objects of a particular class are on a screen, you can instantly put them all into a list and apply the same action to all of them! It takes time to truly grasp how powerful object-oriented programming can be, and how you can harness its objects-first focus to make your own programs concise and elegant. Unfortunately, some programmers dont invest that time. They rely on brute force, repetitive methods resulting in long programs that are, by nature, hard to review and debug. Return to the Greenfoot Gallery (www.greenfoot.org) and download programs by other students currently learning Greenfoot. Many of the students are struggling to embrace elegant and brief methods to, among other things, construct their worlds and apply methods to their objects. Find a program that a) uses at least one loop and a list effectively, or b) could use a loop and a list to improve the program.

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_2

Step: 3

blur-text-image_3

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

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

What is the difference between bossing and coaching a team?

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago