In this assignment you will program a Java class that traverses a list.
This assignment must be submitted to the Moodle submission page for Homework 4 with the name SumSquares.java by 11:00 PM on Thursday, 9 February.
Your program must be written for the
homework4
package.
You should
use the Java class TestDriver
to test your class.
This assignment requires that you use the
IntList
class covered in the Feburary 1 lecture.
This class is written for the
edu.unca.cs.csci202
package, so you must be sure to
place it in this package.
Also, your SumSquares.java should be started with the following Java code.
package homework4 ; import edu.unca.cs.csci202.IntList ;
You are going to implement a single static method
called sumSquares
that receives an
IntList
as its single arugment and returns an
int
.
The returned value is should be the result of adding the squares
of all the integers in the IntList
. If the
list contains the numbers, 202, 13, 39, and 1; your program
should return 42495 (202*202 + 13*13 + 39*39 + 1).
It‘s not hard at all. The innards of the sumSquares
method only needs seven lines of Java!
Here’s a plan of attack.
TestDriver
, IntList
, and SumSquares
.sumSquares
method that does nothing but always return 0.sumSquares
method returns the number of elements
in the list.Do one of these every day and you’ll be done by the due date.