我正在尝试从用户输入要从数组中打印哪个元素的数组中调用一个值,我知道我遇到一个错误,即他们不知道变量Manipulation Array是什么,并且相同与我的歌曲和Artist数组一起使用,但是当我在尝试输出它们之前声明它们时,它只会输出空值,而不是数组元素中的值
package nea2;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class NEA2{
private static Scanner x;
private static String Scannedpassword3;
private static String Verifypass;
public static void main(String[] args) throws FileNotFoundException, IOException {
File userpass = new File("E:\\NEA\\userpass.txt");
File Songs = new File("E:\\NEA\\Songs.txt");
System.out.println("Are you a registered user?");
Scanner scan = new Scanner(System.in);
String Line = scan.nextLine();
String scannedusername;
String scannedpassword;
String scannedpassword2;
String scannedusername2;
String scannedpassword3;
int outcome = 0;
int lives = 2;
if (Line.equals("y") || Line.equals("Y")) {
System.out.println("Enter Username");
scannedusername = scan.nextLine();
System.out.println("Enter Password");
scannedpassword = scan.nextLine();
ConfirmLogin(scannedusername, scannedpassword, userpass);
outcome++;
}
if (Line.equals("n") || Line.equals("N")) {
System.out.println("Create Username");
scannedusername2 = scan.nextLine();
System.out.println("Create Password");
scannedpassword2 = scan.nextLine();
System.out.println("Verify Password");
scannedpassword3 = scan.nextLine();
CreateAccount(scannedusername2, scannedpassword2, scannedpassword3, userpass);
outcome++;
}
ArrayList<String> songs;
int points = 0;
//Spelt ManipulationArray incorrectly (ManipluationArray)
Scanner start = new Scanner(System.in);
String yes;
System.out.println("Are you ready?(yes/no)");
yes = start.nextLine();
switch (yes) {
case "no":
System.out.println("Goodbye.");
System.exit(0);
default:
System.out.println("Say yes to start the quiz.");
System.exit(1);
case "yes":
System.out.println("Quiz starting, be ready");
outcome++;
//Incorrect Range Check
if (outcome > 1)
System.out.println("Please enter a number between 0 and 19");
int input1 = scan.nextInt();
System.out.println(ManipulationArray[20]+","+ArtistArray[20]);
System.out.println("Please enter your guess");
String SongGuess=scan.nextLine();
if (SongGuess.equals(SongArray[input1])) {
System.out.println("Correct,you have gained 3 points" + points+3);
//You don't need to define a new Scanner every time you wish to get an input from the user
//You don't need the to define a variables datatype again (you had String Num here which was already defined as a String previously)
Scanner inputs = new Scanner(System.in);
String Num = scan.nextLine();
//Wrong scanner method
int input = scan.nextInt();
//Incorrect concatenation attempt
String SongArray[] = new String[20];
SongArray[0] = "Me And My Guitar";
SongArray[1] = "Drowning";
SongArray[2] = "DNA";
SongArray[3] = "The Box";
SongArray[4] = "Roxxane";
SongArray[5] = "Dance Monkey";
SongArray[6] = "Dior";
SongArray[7] = "Girls Like You";
SongArray[8] = "Shape Of You";
SongArray[9] = "God's Plan";
SongArray[10] = "Ballin'";
SongArray[11] = "Blueberry Faygo";
SongArray[12] = "Moonlight";
SongArray[13] = "Sad!";
SongArray[14] = "Believer";
SongArray[15] = "Mask Off";
SongArray[16] = "iSpy";
SongArray[17] = "Congratulations";
SongArray[18] = "Happpier";
SongArray[19] = "Godzilla";
String ArtistArray[] = new String[20];
ArtistArray[0] = "A Boogie Wit Da Hoodie";
ArtistArray[1] = "A Boogie Wit Da Hoodie";
ArtistArray[2] = "Kendrick Lamar";
ArtistArray[3] = "Roddy Rich";
ArtistArray[4] = "Arizona Zervas";
ArtistArray[5] = "Tones and I";
ArtistArray[6] = "Pop Smoke";
ArtistArray[7] = "Maroon 5";
ArtistArray[8] = "Ed Sheeran";
ArtistArray[9] = "Drake";
ArtistArray[10] = "Mustard";
ArtistArray[11] = "Lil Mosey";
ArtistArray[12] = "xxxtentaction";
ArtistArray[13] = "xxxtentaction";
ArtistArray[14] = "Imagine Dragons";
ArtistArray[15] = "Future";
ArtistArray[16] = "Kyle";
ArtistArray[17] = "Post Malone";
ArtistArray[18] = "Marshmello";
ArtistArray[19] = "Eminem";
String ManipulationArray[] = new String[20];
ManipulationArray[0] = "M* A** M* G*****";
ManipulationArray[1] = "D*******";
ManipulationArray[2] = "D**";
ManipulationArray[3] = "T** B**";
ManipulationArray[4] = "R******";
ManipulationArray[5] = "D**** M*****";
ManipulationArray[6] = "D***";
ManipulationArray[7] = "G**** L*** Y**";
ManipulationArray[8] = "S**** O* Y**";
ManipulationArray[9] = "G**** P***";
ManipulationArray[10] = "B******";
ManipulationArray[11] = "B******** F****";
ManipulationArray[12] = "M********";
ManipulationArray[13] = "S***";
ManipulationArray[14] = "B*******";
ManipulationArray[15] = "M**** O**";
ManipulationArray[16] = "i***";
ManipulationArray[17] = "C**************";
ManipulationArray[18] = "H******";
ManipulationArray[19] = "G*******";
}
}
}
public static void ConfirmLogin(String scannedusername, String scannedpassword, File userpass) throws FileNotFoundException, FileNotFoundException {
try {
x = new Scanner(userpass).useDelimiter(",");
int outcome = 0;
while (x.hasNext()) {
final String lineFromFile = x.nextLine();
if (lineFromFile.equals(scannedusername + "," + scannedpassword)) {
outcome = outcome + 1;
break;
}
}
if (outcome > 0) {
System.out.println("Login Successful");
} else {
System.out.println("Username or Password is incorrect");
System.exit(0);
}
} catch (Exception e) {
System.out.println("Error file not found");
}
}
public static void CreateAccount(String username2, String scannedpassword2, String scannedpassword3, File userpass) throws FileNotFoundException, IOException {
Verifypass = scannedpassword2;
if (Verifypass.equals(scannedpassword3)) {
System.out.println("Account Creation complete");
Scanner scan = new Scanner(System.in);
FileWriter fWriter;
BufferedWriter writer;
try {
fWriter = new FileWriter(userpass, true);
writer = new BufferedWriter(fWriter);
writer.write(username2 + "," + scannedpassword2);
writer.newLine();
writer.close();
} catch (IOException e) {
System.out.println("Error creating account, Bare with us.");
}
} else {
System.out.println("Passwords do not match");
};
}
}