Objective: Write a program in which the user can: *****I ONLY NEED THE SEARCH ME
ID: 639046 • Letter: O
Question
Objective:
Write a program in which the user can:
*****I ONLY NEED THE SEARCH METHOD FROM VideoGameCollectionManager as i already have everything else done.*****
1. 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.
2. 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.
a. Matches for the game and console entered are returned
b. Partial matches for the name or console are acceptable
c. This is not case sensitive
d. User may use the character
Explanation / Answer
import java.io.*; import java.util.Scanner; public class project2 { public static void main( String[] args ) throws IOException { String[] list; String search = ""; while ( ! search.equals( "quit" ) ) { System.out.println( " Enter a word to search for: " ); Scanner input = new Scanner(System.in); search = input.next(); Scanner file = new Scanner(new File("words.txt")); while(file.hasNextLine()){ String str = file.nextLine(); if(str.indexOf("search") != -1){ System.out.println( "Word '" + search + "' was found");} else System.out.println( "Word '" + search + "' was NOT found");} } } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.