CSCI 202 Homework 4

Purpose

In this assignment you will program a Java class that traverses a list.

Due dates

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.

Starting the assignment

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 ;

The method you write

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).

So how hard is this?

It‘s not hard at all. The innards of the sumSquares method only needs seven lines of Java! Here’s a plan of attack.

  1. Create a NetBeans project with the appropriate classes: TestDriver, IntList, and SumSquares.
  2. Make sure your program compiles and runs for a sumSquares method that does nothing but always return 0.
  3. Have your sumSquares method returns the number of elements in the list.
  4. Finish it up.

Do one of these every day and you’ll be done by the due date.