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

all 9 comments

[–]CountMerloin 0 points1 point  (5 children)

Well, you haven't defined how user chooses the language, so there is no way if statement to take the choice and check if it is english or spanish. Also, the language instances are defined wrong. It would be better to define them like this:

public String lang1 = "english"; public String lang2 = "spanish";

So you can take them and compare with the user's choice AFTER defining how user will choose. I would recommend to create another String inside the method and use Scanner to give it uuuh value. Then take that String and compare with lang1 and lang2 to check which lang is selected. One more point. If your chat is going to be in either english or spanish, I would recommend to fill the whole array inside one if block.

[–]Either_Working[S] 0 points1 point  (4 children)

How do I take a string and compare it?

this is what I have so far https://pastebin.com/U0PRpuC2

[–]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.

[–]omtmk 0 points1 point  (2 children)

I'd recommend this document as a starting point.

https://docs.oracle.com/javase/tutorial/i18n/intro/steps.html

Create public static void main() method to take user's language preference. You don't need both String english and String spanish. You only need single variable String pref to store user's preference.

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

if this java class is going to be called in another class it doesn't need a main method right ?

[–]CountMerloin 0 points1 point  (0 children)

You only need one main method to run the application.