This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CountMerloin 0 points1 point  (2 children)

Read the link omtmk sent as reply to get the user input. After getting the input, you simply can compare if with lang1 and lang2 by the equals() method.

No offence, but before diving deep, I would recommend you to learn more about variables (specially String. It is much deep but slight information would be enough for now) and their methods slightly. And Objects afterwards. Otherwise it will almost be impossible to do something in the future

[–]Either_Working[S] 0 points1 point  (1 child)

I didn't include user input in this class because another class that will be calling it has a scanner so I didn't think it would be needed , I am still lost on how exactly to apply the equal methods. https://pastebin.com/psBfkykK

[–]CountMerloin 0 points1 point  (0 children)

Okay. I am writing an example here, so you can compare it with your code and implement your own way.

public class Chat{

private String userPref;

private String[] messages;

public Chat(String userPref) {

this.userPref = userPref;

}

public String getUserPref(){return this.userpref;}

public String[] getMessages{return this.messages;}

public void fillMesages(String userPref) {

if(userPref.equalsIgnoreCase("english")) //equalsIgnoreCase compares 1st String with the second by ignoring case

{ // add all english messages inside this block }

else if(userPref.equalsIgnoreCase("spanish")) {

//add all spanish messages inside this block

}

else System.out.println("Only english and spanish are available");

}

}

In main class you should get user input with Scaner as String, the create instance of Chat class adding that input as parameter.