现在我将它设置为构造函数,但是我不确定如何实际使用它。我希望能够存储名字、姓氏和学位级别。我需要它继续运行,直到我停止它并继续执行更多程序。
import javax.swing.*;
import java.util.ArrayList;
public class Tutor
{
public Tutor(String firstName, String firstName, String degreeLevel)
{
firstName = firstName;
lastName = firstName;
degreeLevel = degreeLevel;
}
public static void main (String[] args)
{
String fName;
String lName;
String level;
String ans;
ArrayList<String> listOfTutor = new ArrayList<String>();
for (int i = 0; i<listOfTutor.size(); i++)
{
fName = JOptionPane.showInputDialog(null,"Enter Tutor's First Name: ");
lName = JOptionPane.showInputDialog(null,"Enter Tutor's Last Name: ");
level = JOptionPane.showInputDialog(null,"Enter Tutor's Highest Level of Degree: ");
Tutor t = new Tutor(fName,lName,level);
listOfTutor.add(t);
}
}
}
编辑
import javax.swing.*;
import java.util.ArrayList;
public class Tutor
{
String firstName;
String lastName;
String degreeLevel;
public Tutor(String firstName, String lastName, String degreeLevel)
{
this.firstName = firstName;
this.lastName = firstName;
this.degreeLevel = degreeLevel;
}
public static void main (String[] args)
{
String fName;
String lName;
String level;
String ans;
ArrayList<Tutor> listOfTutor = new ArrayList<Tutor>();
for (int i = 0; i<3; i++)
{
fName = JOptionPane.showInputDialog(null,"Enter Tutor's First Name: ");
lName = JOptionPane.showInputDialog(null,"Enter Tutor's Last Name: ");
level = JOptionPane.showInputDialog(null,"Enter Tutor's Highest Level of Degree: ");
Tutor t = new Tutor(fName,lName,level);
listOfTutor.add(t);
}
}
}