Hi there, I am a total newbie. Learning java at uni. One of our questions on classes asks us to write some method statements. here is a snippet of the code:
PersonImproved agent1 = new PersonImproved("Natasha", 99); System.out.println(agent1); agent1.setName("Sophia"); agent1.setAge(24); System.out.println(agent1); PersonImproved agent2 = new PersonImproved("Boris", 40); System.out.println(agent1.equals(agent2)); System.out.println(agent1.isSameName(agent2)); /*System.out.println(agent1.isSameAge(agent2)); agent2.setName("Sophia"); System.out.println(agent2.isSameName(agent1)); agent2.setAge(21); System.out.println(agent2.isSameAge(agent1)); System.out.println(agent1.isYoungerThan(agent2)); agent1.setAge(42); agent2.setAge(42); System.out.println(agent1.isOlderThan(agent2)); agent2.setAge(99); System.out.println(agent2.isOlderThan(agent1)); System.out.println(agent1.isYoungerThan(agent2));*/ }}} class PersonImproved {private String name; private int age; public PersonImproved(String newName, int newAge) {name = newName; if (newAge >= 0) age = newAge; else {System.out.println("ERROR: Used a negative age."); System.exit(0); } } public String getName() {return name; } public void setName(String name) { this.name = name; } public int getAge() {return age; } public void setAge(int age) { this.age = age; } public boolean equals(String name, int age) { return (this.name == name && this.age == age); } public boolean isSameName(String name, int age) { return (this.name == name); } /*public boolean isSameAge(String name, int age) { return (this.age == age); } public boolean isYoungerThan(String name, int age) { return (this.age < age); } public boolean isOlderThan(String name, int age) { return (this.age > age); } public String toString() { return name + " " + age; }*/ }
I am getting this error when compiling:
1 error found:
File: /Users/RichAnge/JPL/H274.java [line: 21]
Error: /Users/RichAnge/JPL/H274.java:21: isSameName(java.lang.String,int) in PersonImproved cannot be applied to (PersonImproved)
and I don't know what this means, can anyone inform me of what the error means so I can fix my code. thanks
(ps: i have some of the code commented out because I am working one line at a time, i hope that is not my problem lol).