I have two letters and for each letter there is a word eg: A-apple, B-bus I need to create a method that returns the words if I provide the letter I was thinking that I could do it this way (method1):
public class Main {
static void method1(String letter) {
if (letter.equals("A") {
System.out.println("apple");
} else if (letter.equals("B") {
System.out.println("bus");
}
}
The problem is that I need another method (method2) that creates another letter and word pair that can be also returned by method1, how can I do this without changing method1? Can I make a dataframe or list that is outside the methods but can be accessed and updated by the methods?
To clarify I need solution for the following task:
- I have pairs which contain 1 letter and 1 word
(for example this is a pair: A-Apple) - I have to create two methods
-
- method should print/return the word from a pair if we provide the letter, so for example if we provide the letter A, then it should print/return the word 'Apple'
- 2.method should somehow creat a new pair that can be later accessed the same way as the above example (A-Apple pair)