I am trying to create a .json file with with part of the filename coming from user input. However I keep getting the null value in the resulted filename: it is nullworkoom.json where null should actually be a string coming from the user.
This is part of my code:
public class WorkRoomApp {
private String name;
//private static final String JSON_STORE = "./data/workroom.json";
private String JSON_STORE = "./data/" + name +"workroom.json";
private Scanner input;
private WorkRoom workRoom;
private JsonWriter jsonWriter;
private JsonReader jsonReader;
// Step 1
public WorkRoomApp() throws FileNotFoundException {
jsonWriter = new JsonWriter(JSON_STORE);
jsonReader = new JsonReader(JSON_STORE);
runWorkRoom(); // Step 2
}
// Step 2
private void runWorkRoom() {
boolean keepGoing = true;
String command = null;
input = new Scanner(System.in);
new_customer(); // Step 3
// Step 3
private void new_customer(){
System.out.println("Are you first time here?");
System.out.print(("Press 1 for yes, and 0 for no"));
input = new Scanner(System.in);
String yes_no;
yes_no = input.next();
if (yes_no == "1"){
create_new_json(); // step 4: because I pretend it is a new user
} else {
load_old_json();
}
}
private void create_new_json(){
System.out.println("Please enter your name without space");
String filename = null;
Scanner input = new Scanner(System.in);
filename = input.next();
this.name = filename; // so I thought the name field in the class
// has not been filled with the actual filename string now.
// so that the field JSON_STORE will not equal
// "./data/ABCworkroom.json"
// if the person enter ABC when asked "Please enter your name without space"
// but somehow I got the file nullworkroom.json
could someone tell me where my mistake could be in the code?
thank you