Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Programming Question: package cscd212lab1; import java.io.*; import java.util.*; import cscd212classes.lab1.*; import cscd212methods.lab1.*; import cscd212comparators.lab1.*; import cscd212utils.fileutils.FileUtils; /** * CSCD212Lab1 is the provided testing file
Java Programming Question:
package cscd212lab1; import java.io.*; import java.util.*; import cscd212classes.lab1.*; import cscd212methods.lab1.*; import cscd212comparators.lab1.*; import cscd212utils.fileutils.FileUtils; /** * CSCD212Lab1 is the provided testing file that contains main. There will also be a JUnit testing file you can uese. * You will not change this file in any fashion. * You will not write any other methods then those specified in the API * NOTE: All parameters passed to methods will be final. You must enforce all preconditions * NOTE: I provided a jar file with the file methods. Don't unzip the jar just add it to the * buildpath. The only thing in the jar file is .class files. */ public class CSCD212Lab1 { /** * The main method used for testing your code and program * @param args Representing the array of Strings being passed in * @throws Exception on the method header to quiet the compiler for the file handling */ public static void main(final String [] args)throws Exception { int choice = 0; Scanner kb = new Scanner(System.in), fin = null; File inputFile = FileUtils.openInputFile(kb); fin = new Scanner(inputFile); ArrayListtheGames = new ArrayList (); CSCD212Lab1Methods.fillArrayList(fin, theGames); fin.close(); do { choice = CSCD212Lab1Methods.menu(kb); if(choice == 1) CSCD212Lab1Methods.printGames(System.out, theGames); else if(choice == 2) Collections.sort(theGames); else if(choice == 3) Collections.sort(theGames, new GamePlayedTimeComparator()); else if(choice == 4) Collections.sort(theGames, new GameStudioNameComparator()); else if(choice == 5) { Game toAdd = CSCD212Lab1Methods.buildGame(kb); int res = theGames.indexOf(toAdd); if(res > -1) System.out.println("Movie found at index " + res); else System.out.println("That movie was not found"); } else if(choice == 6) { Game toAdd = CSCD212Lab1Methods.buildGame(kb); theGames.add(toAdd); theGames.trimToSize(); } else System.out.println("Good Bye"); }while(choice != 7); kb.close(); }// end main }// end class
package cscd212methods.lab1; import cscd212classes.lab1.Game; import cscd212classes.lab1.GameStudio; import cscd212enums.lab1.GameGenre; import java.io.*; import java.util.*; /** * This is the methods class for user interaction. * All paramaters must be passed as final * All preconditions will be enforced * All postconditions will be enforced */ public class CSCD212Lab1Methods { /** * The fill array list method reads a game one line at a time from the file and creates a game object * Look at games.txt file the information about a game on separate lines * @param fin Reprsenting a Scanner object that has wrappered a File object * @param theGames Representing an array list of game objects * @throws IllegalArgumentException if the scanner or arraylist are null with the message Bad Params fillArrayList * NOTE: The scanner input buffer is left empty and the array list is trimmed to size * Below is the file order (game.txt) * game name * game genre * game studio name * game studio city * game studio year * game multiplayer * game played time */ public static void fillArrayList(final Scanner fin, final ArrayListtheGames) { } /** * The build game method prompts the user to enter game information, and builds the appropriate game object * You must build a game studio object before you build a game object. The game studio object will be passed to * the constructor to build a game object. * @param kb Representing a valid Scanner object * @return Game Representing a fully created game object * @throws IllegalArgumentException if kb is null with the string Bad Param build game * POSTCONDITION: The input buffer is left empty (Tip if you only use nextLine it will be empty) */ public static Game buildGame(final Scanner kb) { } /** * This private method receives a string and returns the appropriate matching string of the enumerated type * @param genre Representing the string to be converted to an enumerated constant * @return String Representing the constant value as a capitalized String. * For example the user enters action the method would return AC. * @throws IllegalArgumentException if the string passed in is null or empty * @throws NoSuchElementException if the genre string is not found in the array of GameGenre -- uses values */ private static String findGenre(final String genre) { } /** * The menu method written by me you don't have to write anything * @param kb Representing a valid scanner object * @return int Representing a menu choice in range * @throws IllegalArgumentException if kb is null * POSTCONDITION: Leaves the input buffer empty */ public static int menu(final Scanner kb) { if(kb == null) throw new IllegalArgumentException("Bad Param menu"); int choice; do { System.out.println("Please choose from the following"); System.out.println("1) Print games to the screen"); System.out.println("2) Order the games based on natural order"); System.out.println("3) Order the games based on the total order of time played"); System.out.println("4) Order the games based on the total order of game studio name"); System.out.println("5) Build a game and determine if the game is in the array list"); System.out.println("6) Build a game and add it into the array list"); System.out.println("7) Quit"); System.out.print("Choice --> "); choice = Integer.parseInt(kb.nextLine()); }while(choice < 1 || choice > 7); return choice; }// end menu /** * Print games is provided by me nothing for you to write * @param fout Representing a PrintStream object * @param theGames Representing the array list of games * @throws IllegalArgumentException if fout is null or the games is null */ public static void printGames(final PrintStream fout, final ArrayList theGames) { if(fout == null || theGames == null) throw new IllegalArgumentException("Bad param printGames in Methods class"); for(int x = 0; x < theGames.size(); x++) fout.println(theGames.get(x) + " "); }// end printGames /** * Provided by me and Java for free */ public CSCD212Lab1Methods(){} }// end class
Here is the games.txt file :
Half-Life FPS Valve Bellevue 1996 False 16 Super Mario Bros. PF Nintendo Minami-ku 1889 False 3 Minecraft SB Mojang Studios Stockholm 2009 True 8
I need to write the fillArrayList, buildGame and find genre methods.
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