COE 318 Midterm: COE318 – Fall 2017 Midterm

97 views12 pages

Document Summary

Either indicates that a compiler error would occur, or write the output on the line associated with the code fragment. class cclass{ public static void main(string args[]){ Aclass(int x){ this. x = x; int add(aclass ref){ return x + ref. x; Objects of class x (partial code shown below) manage a collection of widgets (of type widget). Each widget has a value that can be obtained from its getvalue() method. For example, if p is a widget, then p"s value can be obtained with p. getvalue(). The total value of the widgets maintained by an x object is simply the sum of the values of each of its widgets. Write the code to implement the totalvalue() method in class x in the space below. Some methods supported by arraylist objects that may prove useful are: //index in the list public class x { private arraylist widgets = new arraylist();