Question: I began the code but am having trouble to finish it! // write a method that sorts the policies by customer number // this one

I began the code but am having trouble to finish it!

// write a method that sorts the policies by customer number // this one is tougher since you can not use the Collections.sort() method // so you need to just slug out some code. // Look at the bubble sort from the SortByHand in the search_sort package // You will want to do something similar // Here is some pseudocode to help //

public static void sortCustNum(ArrayList insure) {

{

for (int out = insure.size() - 1; out > 1; out--) for (int in = 0; in < out; in++) { // get the first insurance policy Insurance first = insure.get(in); // get the customer from that insurance policy Customer cFirst = first.getCustomer(); // get the customer number from that insurance policy Customer idFirst = cFirst.getId();

// get the second insurance policy Insurance second = insure.get(in+1); // get the customer from that insurance policy Customer cSecond = second.getCustomer(); // get the customer number from that insurance policy Customer idSecond = cSecond.getId();

// We want to check to see if the second customer number is // less than the first one

// NOTE: When comparing customer numbers: // SortByHand uses Strings so it uses the compareTo() // method. // We are comparing integers so we can just use <

// if the second customer number is less than the first one // swap the two insurance policies in the original "insure" // ArrayList // check out the SortByHand to see how to swap. String name1 = first.getLast()+first.getFirst(); String name2=second.getLast()+second.getFirst(); if (name2.compareTo(name1)<0) { c.set(in,second); c.set(in+1,first); }

} } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!