Question: GIVEN CODE(Lab1.java)(FileUtils.java)(SearchUtils.java)(SortUtils.java)(DONT NOT EDIT THESE) GIVEN DOCUMENT (People.txt) Lab1.java: package lab1.cscd211lab1; import java.io.*; import java.util.*; //scanner to kb import lab1.cscd211enums.*; import lab1.cscd210utils.*; import lab1.cscd211classes.*; import

 GIVEN CODE(Lab1.java)(FileUtils.java)(SearchUtils.java)(SortUtils.java)(DONT NOT EDIT THESE) GIVEN DOCUMENT (People.txt) Lab1.java: package lab1.cscd211lab1;

GIVEN CODE(Lab1.java)(FileUtils.java)(SearchUtils.java)(SortUtils.java)(DONT NOT EDIT THESE)

GIVEN DOCUMENT (People.txt)

Lab1.java: package lab1.cscd211lab1;

import java.io.*; import java.util.*; //scanner to kb import lab1.cscd211enums.*; import lab1.cscd210utils.*; import lab1.cscd211classes.*; import lab1.cscd211methods.*; import lab1.cscd211comparators.*; public class CSCD211Lab1 { public static void main(String [] args) throws Exception { File inf = null; int total, choice; Person [] myPeeps = null; Scanner kb = new Scanner(System.in), fin = null; inf = FileUtils.openInputFile(kb); //get the people.txt file fin = new Scanner(inf); total = FileUtils.countRecords(fin, 3); fin.close(); fin = new Scanner(inf); myPeeps = CSCD211Lab1Methods.fillArray(fin, total); SortUtils.selectionSort(myPeeps); //scans for the lowest number fin.close(); do //will always run the do before while { choice = CSCD211Lab1Methods.menu(kb); if(choice == 1) CSCD211Lab1Methods.printArray(myPeeps); else if(choice == 2) { Color toFind = CSCD211Lab1Methods.readColor(kb); //kb (keyboard) CSCD211Lab1Methods.displayAll(toFind, myPeeps); }// end choice == 2 else if(choice == 3) Arrays.sort(myPeeps, new ColorComparator()); else if(choice == 4) Arrays.sort(myPeeps); }while(choice != 5); }// end main }// end class

________________________________________________________________________________

Code#2 (FileUtils.Java)

package lab1.cscd210utils;

import java.util.Scanner; import java.io.*; public class FileUtils {

private FileUtils(){}llconstructor public static int countRecords(final Scanner fin, final int linesPer) { if(fin == null) throw new IllegalArgumentException("Scanner can't be null"); if(linesPer

public static File openInputFile(final String filename) { if(filename == null) throw new IllegalArgumentException("filename is null"); if(filename.isEmpty()) throw new IllegalArgumentException("filename is empty"); File inf = new File(filename); if(inf.exists()) return inf; throw new RuntimeException("File could not be opened"); }// end openInputFile }// end class

__________________________________________________________________________________________________________

Code#3 (SearchUtils.java)

package lab1.cscd210utils; public class SearchUtils> { public static > int linearSearch(final T [] array, final T target) { if(array == null || array.length

}//end class _____________________________________________________________________________________________________________

Code#4 (SortUtils.Java) public class SortUtils> { public static > void selectionSort(T [] array) { if(array == null || array.length

**UNFINISHED CODE(Lab1Methods.java)(Color.java)(ColorComparator.java)(Person.java)

Lab1Methods**

package lab1.cscd211methods;

import java.util.*; import labl.cscd211enums.*; import label.cscd211classes.*; /*

the methods class for the lab */

public class cscd 211Lab1Methods { public static Color convertColor(final String color) { if(color == null || color.isempty()) throw new IllegalArgumentException("Bad string convertColor") return COlor.ValueOf(color.toUpperCase().trim()); //method /* The displayAll method displays all Person objects that contain a specific color. Parameters: toFind - Representing the color to find myPeeps - Representing the Person array Throws: */ public static void displayAll(final Color toFFind, final Person [] myPeeps) { //foreach loop instead of for loop for(Person p:myPeeps) { if(p.getColor().equals(toFind)) System.out.println(p + " "); } } public static Person [] fillArray(final Scanner fin. final int total) { String fn, ln, color; Person[] array = new Person[total]; for(int x = 0; x

} } public static Color readCOlor(final Scanner kb) { String c = null; System.out.print("please enter a color "); c = kb.nextLine(); return convertColor(c) } } _______________________________________________________

Color.java ***

package lab1.cscd211enums;

/* Enum COnstants: BLUE GREEN PURPLE RED */ public enum Color {

RED, GREEN, BLUE, PURPLE;

} public String toString() { return this.toString().charAt(0) + this.toString().substring(1).toLowerCase(); } public String toString() { return this.name().charAt(0) + this.name().substring(1).toLowerCase(); }

_____________________________________________________________________________________

ColorComparator.java***

package lab1.cscd211comparators; import java.util.Comparator;

import lab1.cscd211classes.*; public class ColorComparator implements Comparator //implaments is another word for interface { public in compare(final Person p1, final person p2) { return p1.getColor().compareTo(p2.getColor()); }//end compare

}//end class

______________________________________________________________________________

Person.java**

package lab1.cscd211classes;

import lab1.cscd211enums.*;

public class Person implements Comparable {

private String fn; private String ln; private Color color; public Person(final String fn, final Sting ln, final Color color) { this.fn = fn; this.ln = ln; this.Color = color; } @Override public int compareTo(final Person another) { int res = this.ln.compareTo(another.ln); if(res !=0); return res; int res = this.fn.compareTo(another.fn); if(res !=0); return res; return this.color.compareTo(another.color); } public Color getColor() { return this.color; } @Override public string toString() { return this.fn + " " + this.ln + " " + this.color; //combines the ln, fn, and color } }

Provided is CSCD211 Lab1.java that is an unchangeable Java file. Your task is to complete the program based on the provided main. Some specifications are below; however most of the information is in the provided API. Program flow is prompt the user for the name of the input file. open that file and count the number of records in the file create and fill an array of type person for each record that is in the file. The array is then sorted by calling the compare To of Person A menu is displayed - specifications are below o Specific methods based on the menu choice File Specifications Information on each individual will be in the following format (all lines in the file will end with a carriage return): First name Last name Favorite color Example bubba von bigbelly green sally sue sullivan purple faith hillstrom purple NOTES You must range check all values You must ensure the parameterized type of Person is passed to compare/compare To You need to capitalize the name when you print out the name All parameters will be final and all preconditions will be checked FileUtils, SortUtils and SearchUtils classes are provided and must be used. You must create an input file that allows you to sufficiently test the specifications of this assignment. I have provided the Javadocs from the solution. Please see index.html inside the doc folder. TO TURN IN A zip file, in Canvas of the folder Labl-Enums containing: all java files and packages the input file(s) used to test your program program a test run named cscd211lablout.txt testing all aspects We should be able to download the zip and compile your code, and then run your code. Provided is CSCD211 Lab1.java that is an unchangeable Java file. Your task is to complete the program based on the provided main. Some specifications are below; however most of the information is in the provided API. Program flow is prompt the user for the name of the input file. open that file and count the number of records in the file create and fill an array of type person for each record that is in the file. The array is then sorted by calling the compare To of Person A menu is displayed - specifications are below o Specific methods based on the menu choice File Specifications Information on each individual will be in the following format (all lines in the file will end with a carriage return): First name Last name Favorite color Example bubba von bigbelly green sally sue sullivan purple faith hillstrom purple NOTES You must range check all values You must ensure the parameterized type of Person is passed to compare/compare To You need to capitalize the name when you print out the name All parameters will be final and all preconditions will be checked FileUtils, SortUtils and SearchUtils classes are provided and must be used. You must create an input file that allows you to sufficiently test the specifications of this assignment. I have provided the Javadocs from the solution. Please see index.html inside the doc folder. TO TURN IN A zip file, in Canvas of the folder Labl-Enums containing: all java files and packages the input file(s) used to test your program program a test run named cscd211lablout.txt testing all aspects We should be able to download the zip and compile your code, and then run your code

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!