15-100 PRACTICE TEST 2 (ONLINE)

NOTE: THE FOLLOWING IS ONLY A SAMPLE SET OF THREE PROBLEMS FOR YOUR QUIZ PREPARATION. YOU WILL BE ASKED TO WRITE TWO OF THE FOLLOWING FOR THE QUIZ: insert, remove, filter, or some computation on a collection (e.g., minimum, average, ...). YOU WILL WRITE THESE FOR SOME COLLECTION OF OBJECTS GIVEN TO YOU ON THE QUIZ.


Click on the following link to download a copy of the Java code that you will use for this problem: PracticeTest2.zip

Problem Statement

You are to complete a class named CustomerCollection that implements a collection of customers using an array with up-by-one promotion whose insert and remove semantics are explained below. The insert and remove methods both have void as the return type.

NOTE: The length of the array and the number of elements in the array at each step must match the given output. The array length should be increased only if the array is full when an insert operation is begun (see sample output).

INSERT

The insert method takes one parameter, a Customer to be inserted, and must determine if that Customer is already in the array by searching for the customer's name. If the customer is not in the array, this method stores the new Customer after the last customer currently stored in the array (resizing the array if necessary). If the customer is in the array, swap the customer with the customer immediately in front of it the array (if there is one).

Once you implement the insert method and run InsertTester, you should see the following output:

Initial customer collection is empty...   
CustomerCollection[ numCustomers=0/length=1    ]  

INSERTION TESTS...  
  ]

Inserting Lynette Johnson,Residential,5 cents/min,200 minutes,1 phone line(s)   
  CustomerCollection[ numCustomers=3/length=4     
    customer[0]= Harry Jones,Residential,8 cents/min,100 minutes,1 phone line(s)     
    customer[1]= Mary Smith,Business,4 cents/min,300 minutes,1 phone line(s)     
    customer[2]= Lynette Johnson,Residential,5 cents/min,200 minutes,1 phone line(s)    
  ]

Inserting Fred Beatty,Business,3 cents/min,250 minutes,1 phone line(s)   
  CustomerCollection[ numCustomers=4/length=4     
    customer[0]= Harry Jones,Residential,8 cents/min,100 minutes,1 phone line(s)      
    customer[1]= Mary Smith,Business,4 cents/min,300 minutes,1 phone line(s)     
    customer[2]= Lynette Johnson,Residential,5 cents/min,200 minutes,1 phone line(s)     
    customer[3]= Fred Beatty,Business,3 cents/min,250 minutes,1 phone line(s)   
  ]   

Inserting Susan Zimmerman,Residential,8 cents/min,100 minutes,2 phone line(s)   
  CustomerCollection[ numCustomers=5/length=8     
    customer[0]= Harry Jones,Residential,8 cents/min,100 minutes,1 phone line(s)     
    customer[1]= Mary Smith,Business,4 cents/min,300 minutes,1 phone line(s)     
    customer[2]= Lynette Johnson,Residential,5 cents/min,200 minutes,1 phone line(s)      
    customer[3]= Fred Beatty,Business,3 cents/min,250 minutes,1 phone line(s)     
    customer[4]= Susan Zimmerman,Residential,8 cents/min,100 minutes,2 phone line(s)   
  ] 

Inserting Joseph Barnes,Residential,7 cents/min,150 minutes,2 phone line(s)   
  CustomerCollection[ numCustomers=6/length=8     
    customer[0]= Harry Jones,Residential,8 cents/min,100 minutes,1 phone line(s)     
    customer[1]= Mary Smith,Business,4 cents/min,300 minutes,1 phone line(s)     
    customer[2]= Lynette Johnson,Residential,5 cents/min,200 minutes,1 phone line(s)      
    customer[3]= Fred Beatty,Business,3 cents/min,250 minutes,1 phone line(s)     
    customer[4]= Susan Zimmerman,Residential,8 cents/min,100 minutes,2 phone line(s)     
    customer[5]= Joseph Barnes,Residential,7 cents/min,150 minutes,2 phone line(s)   
  ] 

Inserting Harry Jones,Residential,8 cents/min,100 minutes,1 phone line(s)   
  CustomerCollection[ numCustomers=6/length=8     
    customer[0]= Harry Jones,Residential,8 cents/min,100 minutes,1 phone line(s)     
    customer[1]= Mary Smith,Business,4 cents/min,300 minutes,1 phone line(s)     
    customer[2]= Lynette Johnson,Residential,5 cents/min,200 minutes,1 phone line(s)      
    customer[3]= Fred Beatty,Business,3 cents/min,250 minutes,1 phone line(s)     
    customer[4]= Susan Zimmerman,Residential,8 cents/min,100 minutes,2 phone line(s)     
    customer[5]= Joseph Barnes,Residential,7 cents/min,150 minutes,2 phone line(s)   
  ] 

Inserting Fred Beatty,Business,3 cents/min,250 minutes,1 phone line(s)   
  CustomerCollection[ numCustomers=6/length=8     
    customer[0]= Fred Beatty,Business,3 cents/min,250 minutes,1 phone line(s)     
    customer[1]= Harry Jones,Residential,8 cents/min,100 minutes,1 phone line(s)     
    customer[2]= Mary Smith,Business,4 cents/min,300 minutes,1 phone line(s)      
    customer[3]= Lynette Johnson,Residential,5 cents/min,200 minutes,1 phone line(s)     
    customer[4]= Susan Zimmerman,Residential,8 cents/min,100 minutes,2 phone line(s)     
    customer[5]= Joseph Barnes,Residential,7 cents/min,150 minutes,2 phone line(s)   
  ]

Inserting Bugs Bunny,Business,4 cents/min,25 minutes,1 phone line(s)   
  CustomerCollection[ numCustomers=7/length=8     
    customer[0]= Fred Beatty,Business,3 cents/min,250 minutes,1 phone line(s)     
    customer[1]= Harry Jones,Residential,8 cents/min,100 minutes,1 phone line(s)     
    customer[2]= Mary Smith,Business,4 cents/min,300 minutes,1 phone line(s)      
    customer[3]= Lynette Johnson,Residential,5 cents/min,200 minutes,1 phone line(s)     
    customer[4]= Susan Zimmerman,Residential,8 cents/min,100 minutes,2 phone line(s)     
    customer[5]= Joseph Barnes,Residential,7 cents/min,150 minutes,2 phone line(s)     
    customer[6]= Bugs Bunny,Business,4 cents/min,25 minutes,1 phone line(s)   
  ]  

REMOVE

The remove method takes one parameter, a String, specifying the customer name. It searches for this customer in the array by searching for this name. If the customer is not in the array, the array remains unchanged. If the customer is in the array, the customer is removed from the array leaving the order of the remaining customers unchanged.

Once you implement the remove method and run RemoveTester, you should see the following output:

Initial data loaded into CustomerCollection...   
  CustomerCollection[ numCustomers=6/length=8      
    customer[0]= Harry Jones,Residential,8 cents/min,100 minutes,2 phone line(s)     
    customer[1]= Mary Smith,Business,4 cents/min,300 minutes,2 phone line(s)     
    customer[2]= Lynette Johnson,Business,5 cents/min,200 minutes,1 phone line(s)     
    customer[3]= Fred Beatty,Residential,9 cents/min,250 minutes,1 phone line(s)     
    customer[4]= Susan Zimmerman,Residential,8 cents/min,100 minutes,1 phone line(s)      
    customer[5]= Joseph Barnes,Residential,8 cents/min,150 minutes,1 phone line(s)   
  ]

REMOVAL TESTS...   

Removing Daffy Duck  
  CustomerCollection[ numCustomers=6/length=8      
    customer[0]= Harry Jones,Residential,8 cents/min,100 minutes,2 phone line(s)     
    customer[1]= Mary Smith,Business,4 cents/min,300 minutes,2 phone line(s)     
    customer[2]= Lynette Johnson,Business,5 cents/min,200 minutes,1 phone line(s)     
    customer[3]= Fred Beatty,Residential,9 cents/min,250 minutes,1 phone line(s)     
    customer[4]= Susan Zimmerman,Residential,8 cents/min,100 minutes,1 phone line(s)      
    customer[5]= Joseph Barnes,Residential,8 cents/min,150 minutes,1 phone line(s)   
  ]

Removing Joseph Barnes   
  CustomerCollection[ numCustomers=5/length=8 
    customer[0]= Harry Jones,Residential,8 cents/min,100 minutes,2 phone line(s)     
    customer[1]= Mary Smith,Business,4 cents/min,300 minutes,2 phone line(s)     
    customer[2]= Lynette Johnson,Business,5 cents/min,200 minutes,1 phone line(s)     
    customer[3]= Fred Beatty,Residential,9 cents/min,250 minutes,1 phone line(s)     
    customer[4]= Susan Zimmerman,Residential,8 cents/min,100 minutes,1 phone line(s)      
  ]

Removing Lynette Johnson   
  CustomerCollection[ numCustomers=4/length=8 
    customer[0]= Harry Jones,Residential,8 cents/min,100 minutes,2 phone line(s)     
    customer[1]= Mary Smith,Business,4 cents/min,300 minutes,2 phone line(s)     
    customer[2]= Fred Beatty,Residential,9 cents/min,250 minutes,1 phone line(s)     
    customer[3]= Susan Zimmerman,Residential,8 cents/min,100 minutes,1 phone line(s)      
  ]

Removing Harry Jones   
  CustomerCollection[ numCustomers=3/length=8 
    customer[0]= Mary Smith,Business,4 cents/min,300 minutes,2 phone line(s)     
    customer[1]= Fred Beatty,Residential,9 cents/min,250 minutes,1 phone line(s)     
    customer[2]= Susan Zimmerman,Residential,8 cents/min,100 minutes,1 phone line(s)      
  ]

Removing Susan Zimmerman 
  CustomerCollection[ numCustomers=2/length=8     
    customer[0]= Mary Smith,Business,4 cents/min,300 minutes,2 phone line(s)      
    customer[1]= Fred Beatty,Residential,9 cents/min,250 minutes,1 phone line(s)   
  ] 

Removing Mary Smith 
  CustomerCollection[ numCustomers=1/length=8      
    customer[0]= Fred Beatty,Residential,9 cents/min,250 minutes,1 phone line(s)   
  ]

Removing Fred Beatty   
  CustomerCollection[ numCustomers=0/length=8    
  ]

Removing Susan Zimmerman   
  CustomerCollection[ numCustomers=0/length=8   
  ]  

FILTER extra practice

The filter method takes one parameter, an integer number of minutes, and returns a new CustomerCollection that contains references to all the customer objects in this customer collection that have used at least the number of minutes specified. The order of the object references in the new collection should be the same as the relative order of the selected object references from this collection. If there are no customers that meet this crieria, return a collection with no customers.

Once you implement the filter method and run FiltertTester, you should see the following output:

Initial data loaded into CustomerCollection...
  CustomerCollection[ numCustomers=6/length=8
    customer[0]= Harry Jones,Residential,8 cents/min,100 minutes,2 phone line(s)
    customer[1]= Mary Smith,Business,4 cents/min,300 minutes,2 phone line(s)
    customer[2]= Lynette Johnson,Business,5 cents/min,200 minutes,1 phone line(s)
    customer[3]= Fred Beatty,Residential,9 cents/min,250 minutes,1 phone line(s)
    customer[4]= Susan Zimmerman,Residential,8 cents/min,100 minutes,1 phone line(s)
    customer[5]= Joseph Barnes,Residential,8 cents/min,150 minutes,1 phone line(s)
  ]


FILTER TESTS...

Create a new collection of customers who used at least 120 minutes.
  CustomerCollection[ numCustomers=4/length=4
    customer[0]= Mary Smith,Business,4 cents/min,300 minutes,2 phone line(s)
    customer[1]= Lynette Johnson,Business,5 cents/min,200 minutes,1 phone line(s)
    customer[2]= Fred Beatty,Residential,9 cents/min,250 minutes,1 phone line(s)
    customer[3]= Joseph Barnes,Residential,8 cents/min,150 minutes,1 phone line(s)
  ]

Create a new collection of customers who used at least 200 minutes.
  CustomerCollection[ numCustomers=3/length=4
    customer[0]= Mary Smith,Business,4 cents/min,300 minutes,2 phone line(s)
    customer[1]= Lynette Johnson,Business,5 cents/min,200 minutes,1 phone line(s)
    customer[2]= Fred Beatty,Residential,9 cents/min,250 minutes,1 phone line(s)
  ]

Create a new collection of customers who used at least 350 minutes.
  CustomerCollection[ numCustomers=0/length=1
  ]