1 Replies - 77 Views - Last Post: 13 September 2012 - 07:00 AM Rate Topic: -----

#1 spacelady  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 24-April 12

Question on using collections and for each an terator construct

Posted 13 September 2012 - 06:39 AM

Hi I have been given 4 classes to complete but I have a problem with the insurancePolicy class because when i read our task specifications an look at the template I do not understand what exactly I have to put an I would just like some clarification. We have to make use of the collection classes in particular the set and map collections an we have to use the for each construct an the iterator. The full program will keep track of the insurance policies of a range of customers for an insurance company.Here is the task specification for the insurancepolicy class.

Complete the InsurancePolicy class to represent an insurance policy. This class needs to have a
Set which will contain the particular CoverType objects that represent the insurance cover
desired by the customer. Methods you need to write/complete are:
· includeCover ( CoverType ) – which should note the specified type of insurance cover as
being included in this insurance policy.
· getPolicyCost – to return the total cost of the policy which is $100 plus the sum of all the
included types of insurance cover.
· lodgeAnotherClaim (CoverType) – which should increase a counter that keeps track of how
many times the person makes a claim against this policy. The parameter specifies which
type of cover the claim is being lodged for. If the policy does not include that type of cover,
then the counter is not increased.
· toString – which should display the policy number, and list the types of cover included in
the policy, as well as the total number of claims made so far. You should make use of an
Iterator to show all the types of cover.


Here are the two classes first the covertype class which I already completed an the insurancepolicy class


import java.util.*;

// Class:   CoverType
// Purpose: Represents a type of insurance cover that can be included on a policy.

// YOU SHOULD NOT NEED TO MODIFY THIS CLASS.

public class CoverType
{
	private String name;		// The name of this type of insurance cover
	private int price;			// The price of this type of insurance cover
	
	// a universal (i.e. not instance specific) attribute for keeping all known CoverTypes.
	private static ArrayList<CoverType> allTypes = null;
	
	// Constructor - deliberately not public.
	protected CoverType(String name, int price)
	{
		this.name = name;
		this.price = price;
	}
	
	public String getName()
	{
		return name;
	}
	
	public int getPrice()
	{
		return price;
	}
	
	
	// static Method:  getCoverTypesList
	// Purpose:  It returns a List containing all the CoverTypes that are available in this program.
	public static List<CoverType> getCoverTypesList()
	{
		if (allTypes == null)		// Means that this method has not previously been called
		{
			// So we need to set up the system to contain the following hard-coded cover types
			allTypes = new ArrayList<CoverType>();
			
			allTypes.add( new CoverType("Fire",250) );		// Protection against fire
			allTypes.add( new CoverType("Flood",175) );		// Protection against flood
			allTypes.add( new CoverType("Storm Damage",160) );	// etc.
			allTypes.add( new CoverType("Theft",420) );	
		}
		
		// give back an ArrayList that contains the above cover types...
		return (List<CoverType>) allTypes.clone();
	}
}




An here is the insurance policy class


// Class:   InsurancePolicy
// Purpose: To represent a particular customer's insurance agreement
public class InsurancePolicy {
	
	// Each instance will have a unique policy number.
	private int policyNumber;
	
	private static int nextPolicy = 1;
	
	public InsurancePolicy()
	{
		this.policyNumber = nextPolicy;
		nextPolicy++;
	}
	
	// Determine this policy's number
	public int getPolicyNumber()
	{
		return policyNumber;
	}
	
	// Method:  getPolicyCost
	// Purpose: to report to the caller, the total cost of this policy, based on the covers
	//          that are selected
	public int getPolicyCost()
	{
		// must replace the following...
		return 0;
	}
	
	// Method:  includeCover
	// Purpose: To allow the caller to specify a type of insurance cover to be included for this policy.
	// Returns: True if the cover is now included; if it was already included or was unable to
	//          be included this time, false is returned.
	public boolean includeCover(CoverType which)
	{
		// must replace this following:
		return true;
	}
	
	// Method:  lodgeAnotherClaim
	// Purpose: To increase the counter of how many claims have been made against this policy.
	// Parameter: lodgedType - specifies the type of cover being claimed. But only the types which
	//            have been included so far, will actually be countable.
	public void lodgeAnotherClaim(CoverType lodgedType)
	{
		// must complete
	}
	
	// Method:  toString
	// Purpose: Display a textual summary of this object's state
	@Override public String toString()
	{
		// must complete
		
		return "Something";
	}
}



if I could get clarification what to do in the individual methods which have been marked "must be completed" I would realy appreciate it thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Question on using collections and for each an terator construct

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9038
  • View blog
  • Posts: 33,525
  • Joined: 27-December 08

Re: Question on using collections and for each an terator construct

Posted 13 September 2012 - 07:00 AM

This is something you should really talk to your instructor about. We are happy to help with your good faith efforts, but we aren't here to walk you through your homework.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1