我有一个名为faculty 的类,它带有添加faculty 属性的方法。我已经实现了方法askModel() askSerial() 并将它们作为参数传递给我的box.java 的构造函数...。问题是我该怎么做我的属性被附加到我在我的 Main 中的列表中。
编辑: 对于上面的问题,我试图归档下面的代码。它现在按预期工作。
package first_;
import java.util.InputMismatchException;
import java.util.Scanner;
public class faculty extends person {
double salary;
String title;
double yearsINservice;
public faculty(){
super();
this.salary = salary;
this.title = title;
this.yearsINservice = yearsINservice;
}
/*Name Age is an abstract Method from superClass Person*/
public void nameAge(){
setFirstName(scanfirstName());
setLastName(scanlastName());
setAge(scanage());
setSalary(scansalary());
setTitle(scantitle());
setYearsINservice(scanyearsINservice());
}
/*Address is a SuperClass extended by Abstract class Person*/
public void addressparamaters(){
setHouseNum(scnhouseNum());
setStreetName(scnstreeetName());
setCity(scnCity());
setState(scnState());
setZip(scnZip());
}
/*SETTERS AND GETTERS */
public double getSalary() {return salary;}
public void setSalary(double salary) {this.salary = salary;}
public String getTitle() {return title;}
public void setTitle(String title) {this.title = title;}
public double getYearsINservice() { return yearsINservice;}
public void setYearsINservice(double yearsINservice) {this.yearsINservice = yearsINservice;}
public int scansalary(){
int salary;
System.out.println("Please Enter The Monthly Salary");
salary = scan.nextInt();
return salary;
}
public String scantitle(){
String title = "";
System.out.println("Please Enter The Title");
title = scan.next();
return title;
}
public double scanyearsINservice(){
double yearsINservice = 0;
System.out.println("Please Enter The Number of Years in Service");
salary = scan.nextDouble();
return yearsINservice;
}
public String scanfirstName(){
String firstname = "";
System.out.println("Please Enter First Name");
boolean notDone = true;
while(true){
try{
firstname = scan.next();
break;
}catch(InputMismatchException e){
scan.nextLine();
System.out.println(e.getMessage());
System.out.println("Please a valid Name format");
continue;
}
}
return firstname;
}
public String scanlastName(){
String lastname = "";
System.out.println("Please Enter Last Name");
lastname = scan.next();
return lastname;
}
public double scanage(){
double age= 0 ;
System.out.println("Please Enter Age");
boolean notDone = true;
while(notDone) {
try{
age = scan.nextDouble();
break;
} catch (InputMismatchException e) {
scan.nextLine();
System.out.println(e.getMessage());
System.out.println("Please a valid age format");
continue;
}
}
return age;
}
@Override
public String toSTring() {
return "\n First Name:" + " " + firstName +
"\n Last Name : " +" "+ lastName +
"\n Age : " +" "+ age +
"\n Salary : " + " " + salary +
"\n Title : " + " "+ title +
"\n yearsINservice : " +" "+ yearsINservice +
"\n HOUSE NUMBER:" + " " + houseNum +
"\nStreet Name : " +" "+ streetName +
"\nCity : " +" "+ City +
"\n State: " +" "+ State +
"\n Zip: " +" "+ zip;
}
}