Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use JAVA to solve this, thanks in advanced. Will rate best answer as soon

ID: 638915 • Letter: P

Question

Please use JAVA to solve this, thanks in advanced. Will rate best answer as soon as I verify it works exactly as shown in the Example Dialog. Please comment if you need more information or have a question.

Objective:

Write a program in which the user can:

Read a video game collection file. The file is assumed to have the name and the console and its tab delimited. It is advisable to put each of the games in an ArrayList since number of games is not known.

Search the contents of the file that has already been loaded in from part 1. The user enters the name of the game and then the name of the console.

Matches for the game and console entered are returned

Partial matches for the name or console are acceptable

This is not case sensitive

User may use the character

Explanation / Answer

Program code:
//VideoGame class that holds the

//name of the game and console

public class VideoGame

{

     //instance variables

     String gameName;

     String gameConsole;

     //constructor

     public VideoGame(String gameN, String gameC)

     {

          gameName=gameN;

          gameConsole=gameC;

     }

    

     //getter and setter methods

     public String getGameName()

     {

          return gameName;

     }

     public void setGameName(String gameName)

     {

          this.gameName = gameName;

     }

     public String getGameConsole()

     {

          return gameConsole;

     }

     public void setGameConsole(String gameConsole)

     {

          this.gameConsole = gameConsole;

     }

}

//import the required packages

import java.io.*;

import java.util.*;

//VideoGameCollectionManager class

public class VideoGameCollectionManager

{

     //instance variables

     ArrayList<VideoGame> videogame=new ArrayList<VideoGame>();

     ArrayList<VideoGame> sList=new ArrayList<VideoGame>();

    

     //constructor

     public VideoGameCollectionManager(String filename)throws Exception

     {

          readData(filename);

     }

     //readData method that reads data from

     //a file

     public void readData(String fname)throws Exception

     {

          Scanner in=new Scanner(new File(fname));

          String str[]=new String[2];

          String line="";

          while(in.hasNextLine())

          {

              line=in.nextLine();

              str=line.split(" ");

              System.out.println("str1: "+str[0]+" Str2: "+str[1]);

              VideoGame vg=new VideoGame(str[0],str[1]);

              videogame.add(vg);

          }        

     }

     //search method that searches for the proper string

     //and adds them to new ArrayList

     //and returns the list

     public ArrayList<VideoGame> search()

     {

          Scanner in=new Scanner(System.in);

          System.out.println("Enter the name of the game or '*' for all names: ");

          String name=in.nextLine();

          System.out.println("Enter the name of the console or '*' for all consoles: ");

          String console=in.nextLine();

          for(int i=0;i<videogame.size();i++)

          {

              if(videogame.get(i).getGameName().contains(name)||

                        videogame.get(i).getGameConsole().contains(console))

              {

                   sList.add(videogame.get(i));

              }

          }

          return sList;

     }

    

     //printToFile method that prints the

     //data either by appending or

     //by rewriting to the file

     void printToFile(ArrayList<VideoGame> vg) throws IOException

     {

          Scanner in=new Scanner(System.in);

          System.out.println("Enter the file name to print out.");

          String filename=in.next();

          File f=new File(filename);

          boolean flag=false;

         

          if(!f.exists())

          {

              f.createNewFile();

          }

          System.out.println("Append to file? True or false.");

          flag=in.nextBoolean();

         

          if(!flag)

          {

              FileWriter fileWritter = new FileWriter(f.getName(),flag);

              PrintWriter pw=new PrintWriter(fileWritter);        

              for(int i=0;i<vg.size();i++)

              {

                   pw.write(vg.get(i).getGameName()+" "+vg.get(i).getGameConsole());

                   pw.write(" ");

              }

              pw.close();

              fileWritter.close();

          }

          else

          {

              PrintWriter pw=new PrintWriter(f);        

              for(int i=0;i<vg.size();i++)

              {

                   pw.write(vg.get(i).getGameName()+" "+vg.get(i).getGameConsole());

                   pw.write(" ");

              }

              pw.close();

          }        

     }

}

//import the required packages

import java.io.File;

import java.util.*;

//implementation class

public class VideoGameCollectionFrontEnd

{

     //class variable

     static VideoGameCollectionManager vgcm;

     //main method

     public static void main(String args[])throws Exception

     {

          //declare the required instance variables

          ArrayList<VideoGame> video=new ArrayList<VideoGame>();

          Scanner in=new Scanner(System.in);

          int choice;

          String filename;

          //prompt the user for the inputfile

          System.out.println("Enter the file name: ");

          filename=in.next();

         

          //print the menu to the user

          System.out.println("Welcome to the video game database!");

          do

          {   

              //menu

              System.out.println("Enter 1 to load the video game database");

              System.out.println("Enter 2 to search the database");

              System.out.println("Enter 3 to print current results");

              System.out.println("Enter 4 to print current results to file");

              System.out.println("Enter 0 to quit");

              System.out.println("");

              //enter the choice

              choice=in.nextInt();

              //depending on the choice, the respective

              //cases are invoked

              switch(choice)

              {

                   case 1:

                        vgcm=new VideoGameCollectionManager(filename);

                        break;

                   case 2:

                        video=vgcm.search();

                        break;

                   case 3:

                        System.out.println("The list of games in the current list are: ");

                        for(int i=0;i<video.size();i++)

                             System.out.println(video.get(i).getGameName()+" "+video.get(i).getGameConsole());

                        break;

                   case 4:

                        vgcm.printToFile(video);

                        break;

                   case 0:

                        System.exit(0);

                        break;

                   default:

                        System.out.println("Please enter the correct input.");

              }

          //continuous loop

          }while(true);

     }

}

------------------------------------------------------------------------------------------------------------------------------------------

Sample Input: JJCollection.txt

10-Yard Fight (5 Screw Cartridge) Nintendo Entertainment System [US]

3-D Worldrunner (5 Screw Cartridge)   Nintendo Entertainment System [US]

3DO - Panasonic FZ-1 [NA]    3DO Hardware

720 °     Nintendo Entertainment System [US]

8 Eyes    Nintendo Entertainment System [US]

Action 52 Nintendo Entertainment System [US]

"Addams Family, The"    Nintendo Entertainment System [US]

Adventure Atari 2600 [NA]

"Adventures of Bayou Billy, The" Nintendo Entertainment System [US]

"Adventures of Rad Gravity, The" Nintendo Entertainment System [US]

Airwolf   Nintendo Entertainment System [US]

Anticipation Nintendo Entertainment System [US]

Armor Ambush (Black Label)   Atari 2600 [NA]

Armor Ambush (Black Label)   Atari 2600 [NA]

Asteroids (Black Picture Label)   Atari 2600 [NA]

Astroblast (Black Label)     Atari 2600 [NA]

Atari 2600 (4 Switch) [NA]   Atari 2600 Hardware

Atari 5200 (4 Ports)    Atari 5200 Hardware

Atari 7800 [NA]    Atari 7800 Hardware

Atari Jaguar [NA] Atari Jaguar Hardware

Atlantis (Picture Label - Day Scene) Atari 2600 [NA]

Attack of the Killer Tomatoes     Nintendo Entertainment System [US]

B.C.'s Quest for Tires ColecoVision [NA]

Sample Output:

Enter the file name:

JJCollection.txt

Welcome to the video game database!

Enter 1 to load the video game database

Enter 2 to search the database

Enter 3 to print current results

Enter 4 to print current results to file

Enter 0 to quit

1

Enter 1 to load the video game database

Enter 2 to search the database

Enter 3 to print current results

Enter 4 to print current results to file

Enter 0 to quit

2

Enter the name of the game or '*' for all names:

Atari

Enter the name of the console or '*' for all consoles:

*

Enter 1 to load the video game database

Enter 2 to search the database

Enter 3 to print current results

Enter 4 to print current results to file

Enter 0 to quit

3

The list of games in the current list are:

Atari 2600 (4 Switch) [NA]   Atari 2600 Hardware

Atari 5200 (4 Ports)    Atari 5200 Hardware

Atari 7800 [NA]    Atari 7800 Hardware

Atari Jaguar [NA] Atari Jaguar Hardware

Enter 1 to load the video game database

Enter 2 to search the database

Enter 3 to print current results

Enter 4 to print current results to file

Enter 0 to quit

4

Enter the file name to print out.

Atari.txt

Append to file? True or false.

false

Enter 1 to load the video game database

Enter 2 to search the database

Enter 3 to print current results

Enter 4 to print current results to file

Enter 0 to quit

0

Sample Output file: Atari.txt

Atari 2600 (4 Switch) [NA]   Atari 2600 Hardware

Atari 5200 (4 Ports)    Atari 5200 Hardware

Atari 7800 [NA]    Atari 7800 Hardware

Atari Jaguar [NA] Atari Jaguar Hardware

Note:

Please check with the name of the game to be placed in the next line.

The previous end of the line should not contain any spaces.

Check with the tab spaces.

I have worked with few lists by adjusting the spaces and tabs.

Please do the rest of the list.