I've been trying to wreck my brain around this for days. I need to make a method that is going to ask for the user input via the keybaord. I've written it as
private static String getFromUser(String question){
String s = " ";
System.out.print(question);
while(in.hasNext()){
s = in.next();
//return s;
}
return s;
}
or
private static String getFromUser(String question){
String s;
System.out.print(question);
s = in.nextLine();
return s;
}
HOWEVER When I "uncomment" a skeleton code:
public static void create() {
in = new Scanner(System.in);
String name = "";
String address = "";
//ask the user for the name and address of the company receiving the invoice
//String name = getFromUser("name of company to invoice"); // ******TASK ONE******
//String address = getAddress(); // ******TASK TWO******
It keeps stating : "variable name is already defined in method create()". BUT I'm not allowed to change the codes that has already been written. HENCE, I'm only allowed to remove the "//" comment lines. Do I just return a string or would I require to use method overloading ( I don't fully understand method overloading, tbh). Please Advice or give tips. Thank you very much.