Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package osu.cse 3 2 4 1 . options; import java.sql . Connection; import java.sql . PreparedStatement; import java.sql . ResultSet; import java.sql . SQLException; import
package osu.cseoptions;
import java.sqlConnection;
import java.sqlPreparedStatement;
import java.sqlResultSet;
import java.sqlSQLException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import osu.cseGRS;
import osu.cseutilities.Utilities;
public class SearchArtistTrack
private static Set MENUOPTIONS new HashSetArraysasListx;
public static void menuScanner cin
Utilities.printDivider;
System.out.printSEARCH:
Artists
Tracks
"Input numerical selection or x to quit: ;
String input cin.nextLine;
char selection input.isEmpty input.charAt : ;
while MENUOPTIONS.containsselection
System.out.printIncorrect option specified! Try again: ;
input cin.nextLine;
selection input.isEmpty input.charAt : ;
switch selection
case :
searchArtistscin;
break;
case :
searchTrackscin;
break;
case x:
System.out.printlnExiting;
System.exit;
break;
default:
break;
Search tracks in the database according to input track name.
@param cin scanner
private static void searchTracksScanner cin
System.out.printInput track name or x to quit: ;
String trackName cin.nextLine;
if trackName.equalsx && trackName.trimisEmpty
String sql "SELECT trackname FROM tracks WHERE trackname LIKE ;
try Connection conn GRSgetConnection;
PreparedStatement pstmt conn.prepareStatementsql
pstmtsetString trackName ;
ResultSet rs pstmtexecuteQuery;
System.out.printlnMatching tracks:";
while rsnext
System.out.printlnrsgetStringtrackname";
catch SQLException e
System.out.printlnError executing SQL query: egetMessage;
Search artists in the database according to input artist name.
@param cin scanner
private static void searchArtistsScanner cin
Utilities.placeholder;
TODO: Implement searching artists by artist name
Example:
System.out.printInput artist name or x to quit: ;
String artistName cin.nextLine;
if artistName.equalsx && artistName.trimisEmpty
String sql "SELECT artistname FROM artists WHERE artistname LIKE ;
try Connection conn GRSgetConnection;
PreparedStatement pstmt conn.prepareStatementsql
pstmtsetString artistName ;
ResultSet rs pstmtexecuteQuery;
System.out.printlnMatching artists:";
while rsnext
System.out.printlnrsgetStringartistname";
catch SQLException e
System.out.printlnError executing SQL query: egetMessage;
public static void mainString args
Scanner cin new ScannerSystemin;
while true
menucin;
fill in the todo
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