So we have to have two classes so i set it up good and it was almost exactly like my friends who's worked but mine gives me two errors.
Here are the two classes.
//Lab 2: 8.13 import java.util.*; public class PhoneBookList { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String[] nameList = new String[5]; String[] numberList = new String[5]; PhoneBook entry = new PhoneBook(); System.out.println("Please enter a name then their corresponding " + "number. (dashes not included): Press enter after each name and number "); for(int i = 0; i < nameList.length; i++) { entry.getName(keyboard.nextLine()); nameList[i] = entry.getName(); entry.getNumber(keyboard.nextLine()); numberList[i] = entry.getNumber(); } System.out.println("The Names and Numbers in this phone book are"); System.out.println("Names/t/t/tNumbers"); System.out.println("**************************"); for (int i = 0; i <nameList.length; i++) { System.out.println(nameList[i]+ "/t/t/t"+ numberList[i]); } } }
//Lab 2: 8.13 import java.util.*; public class PhoneBook { private String friend; private String numbers; //Create Array Lists ArrayList<String> nameList = new ArrayList<String>(); ArrayList<String> numberList = new ArrayList<String>(); //Set Name Field public void setName(String name) { nameList.add(name); friend = name; } //Get Name Field public String getName() { return friend; } //Set Number for Name public void setNumber(String num) { numberList.add(num); numbers = num; } //Get Number for same Name public String getNumber() { return numbers; } }
The Errors i recieve are:
E:\Lab 2\PhoneBookList.java:20: getName() in PhoneBook cannot be applied to (java.lang.String)
entry.getName(keyboard.nextLine());
^
E:\Lab 2\PhoneBookList.java:22: getNumber() in PhoneBook cannot be applied to (java.lang.String)
entry.getNumber(keyboard.nextLine());
^
Any help? i put it in right but its saying it cant be applied to string which i dont know why.
Any help would be greatly appreciated.