subject

The bigger picture - the objectlist (or arraylist (v1.0)) class a picture is simply a composition of shapes, and in this last section, we'll build a class used to manage such a picture. we'll create this new class by reusing code from an existing piece of software. we'll create an objectlist class that will contain, amongst other state items (data), an array (or list) of objects that are the squares and circles in the picture to be drawn. objectlists will be a simple abstraction here, and will just "draw shapes to the console in the order that they appear in the list-ignoring the coordinate pairs stored in each shape for now. again, note the static storage restriction of only 100 shapes per picture; in future sections, we'll learn how to dynamically resize our arrays. aside: when we get to working with any of the java graphics framework classes and/or swing, then a simple use of this objectlist class (called a picturepanel extending jpanel) would accommodate for much more interesting shape behaviors and interactions. 1. copy-and-paste the intlist. java code into a new file called objectlist. java a. note this is the same process we used to quickly create the circle. java class 2. change the class name from intlist to objectlist. 3. change the instance variable that is your int[] array to an object ( array called myshapes. 4. change your public void add(int nx)" method to "public void add(object nx)" 5. remove functions and savel) and recompile using the provided shapes picture driver. java driver. 6. run your main and notice it still processes a list of integers correctly 7. now run the driver code and uncomment the objectlist segment and execute it. data members private object(myshapes; // used to be "data" this is an array of type object, which can thus store any object of any class . what about primitives? private int numelements; o this integer tracks the number of live shapes in our array method members void add object shape); o this function adds the circle or square to the array of circles @override public string tostring(): { //iterates through the array, calling tostring() on each shape and appending this //to one large string to be returned sample output alternate sample output questions & observations answer the following questions as multi-line comments in your code.. (1) why did we do so much copying-and-pasting in our software above? a. how can this approach be problematic? (2) are there obvious improvements that could be made here with respect the software design for squares and circles? (3) what programming constructs were you familiar with, and which did you need to look up? (4) assume we used a separate array for squares and for circles rather than one unifying object array. a. how would this complicate the task of adding a new shape (say, a triangle) to our objectlist class?

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 18:00
File account.java (see previous exercise) contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and return a string representation. note that the constructor for this class creates a random account number. save this class to your directory and study it to see how it works. then write the following additional code: 1. suppose the bank wants to keep track of how many accounts exist. a. declare a private static integer variable numaccounts to hold this value. like all instance and static variables, it will be initialized (to 0, since it’s an int) automatically. b. add code to the constructor to increment this variable every time an account is created. c. add a static method getnumaccounts that returns the total number of accounts. think about why this method should be static - its information is not related to any particular account. d. file testaccounts1.java contains a simple program that creates the specified number of bank accounts then uses the getnumaccounts method to find how many accounts were created. save it to your directory, then use it to test your modified account class.
Answers: 3
question
Computers and Technology, 24.06.2019 00:00
Which tool could be used to display only rows containing presidents who served two terms
Answers: 3
question
Computers and Technology, 24.06.2019 03:30
It is not necessary to develop strategies to separate good information and bad information on the internet. true or false
Answers: 1
question
Computers and Technology, 24.06.2019 11:00
Which of the statements below describe the guidelines for the use of text in presentation programs? a. do not use numbered lists. b. fonts should be appropriate for your audience. c. limit the number of fonts you use to three or four. d. only use bulleted lists for sales promotions. e. select font sizes that are appropriate for your delivery method. f. use font colors that work well with your background. select all that apply
Answers: 1
You know the right answer?
The bigger picture - the objectlist (or arraylist (v1.0)) class a picture is simply a composition of...
Questions
Questions on the website: 13722367