So I'm trying to create a program that uses a classes that implements an interface. The idea is the interface has the base stats for all possibles, like all people who use a university, while the classes are more specific, such as faculty. The user gives their first and last name, M Number (essentially an ID), and whether they are full or part time. I'm not trying to check if it exists already or anything complicated: just create the object, then output a line that says it was created.
Here's the code:
Interface:
package assignment1;
import java.util.Scanner;
public interface Person {
String firstName, lastName, mNumber;
void setName(String fName, String lName){
firstName = fName; lastName = lName; }
String getName(){
String fullName = this.firstName.concat(" " + this.lastName);
return fullName; }
void setMNumber(String mNum){
mNumber = mNum; }
String getMNumber(){
return mNumber; }
}
Class:
package assignment1;
import java.util.Scanner;
public class Faculty implements Person {
void actionPerformed(java.awt.event.ActionEvent ev){ }
String Type;
public Faculty(){ }
public void defineType(String type){
this.Type = type;
}
String getType(){
return this.Type; }
void print(){
System.out.println(" A new faculty " + this.getName() +
"M-Number: " + this.getMNumber() + " Type: " +
this.Type + " has been created.");
}
public static void main(String[] args){
Faculty f1 = new Faculty();
Scanner scant = new Scanner(System.in);
String fName = scant.next();
String lName = scant.next();
f1.setName(fName, lName);
String MNum = scant.next();
f1.setMNumber(MNum);
String T = scant.next();
f1.defineType(T);
f1.print();
}
}
The problem comes when I try to run this. No matter what kind of input I give, or through all of my other attempts at fixing it, I get the following error after giving an input:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The type Faculty must implement the inherited abstract method Person.setName(String, String)
at assignment1.Faculty.setName(Faculty.java:5)
at assignment1.Faculty.main(Faculty.java:28)
If anyone could tell me what I'm doing wrong, explain why it's wrong, and tell me how to fix it, it would be greatly appreciated.