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
{
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started