在Eclipse上添加/修改/删除列表项

时间:2017-10-27 13:38:36

标签: java eclipse

我的应用程序开发课程的任务让我们为牙医创建办公系统。 以下要求是:

  • 必须显示牙医,助理,患者和服务的当前列表
  • 必须允许用户添加/编辑/删除此列表中的项目
  • 必须根据所选服务显示客户发票

我的主要问题围绕作业的添加/编辑/删除部分。我想知道哪种方法最适合这样做。但他确实使用了我们不应该使用数据库的指导原则。

以下是我到目前为止的情况。注意:我不需要所有四个列表的代码,如果我有一个,我应该能够找出其他列表。

import java.util.Scanner;

	public class DentistOffice 
	{
		public static void main(String[] args) 
		{
			Scanner sc = new Scanner (System.in);
			
			Patient pat1 = new Patient ("1","James","Mack","123 ABC Street","7701234567");
			Patient pat2 = new Patient ("2","Mark","Smith","456 DEF Street","6784444444");
			Patient pat3 = new Patient ("3","Doug","Barker","789 GHI Avenue","5558889999");
			
			Doctor doc1 = new Doctor ("001","Melanie","Jones","555 Doctor Avenue","DDS");
			Doctor doc2 = new Doctor ("002","Melissa","Roberts","777 Oak West","DMD");
			Doctor doc3 = new Doctor ("003","Luke","Skywalker","333 Toshe Station","DDS");
			Doctor doc4 = new Doctor ("004","Han","Solo","111 Millenium Drive","DMD");
			
			System.out.println("***************************************************************");
			System.out.println("                    Kennesaw Dental Office                     ");
			System.out.println("***************************************************************");
			System.out.println("1. Display Patient List");
			System.out.println("2. Display Doctor List");
			System.out.println("3. Display Assistant List");
			System.out.println("4. Display Service Fees");
			System.out.println("5. Edit Patient List");
			System.out.println("6. Edit Doctor List");
			System.out.println("7. Edit Assistant List");
			System.out.println("8. Edit Service Fees");
			System.out.println("9. Issue Patient Invoice");
			System.out.println("0. Exit the Program");
			
			System.out.println("Please select an option: ");
			
			int option = sc.nextInt();
			switch(option)
			
			{
			case 1: 
				System.out.println("***************************************************************************");
				System.out.println("                                   Patients                                ");
				System.out.println("***************************************************************************");
				System.out.println("Number"+" "+"First Name"+" "+"Last Name"+" "+"Address"+" "+"Phone Number");
				System.out.println(pat1.getIdentification()+pat1.getFirstName()+pat1.getLastName()+pat1.getAddress()+pat1.getPhoneNumber);
				System.out.println(pat2.getIdentification()+pat2.getFirstName()+pat2.getLastName()+pat2.getAddress()+pat2.getPhoneNumber);
				System.out.println(pat3.getIdentification()+pat3.getFirstName()+pat3.getLastName()+pat3.getAddress()+pat3.getPhoneNumber);
				break;
			
			case 2:
				System.out.println("***************************************************************************");
				System.out.println("                                   Doctors                                 ");
				System.out.println("***************************************************************************");
				System.out.println("Number"+" "+"First Name"+" "+"Last Name"+" "+"Address"+" "+"Specialization");
				System.out.println(doc1.getIdentification()+doc1.getFirstName()+doc1.getLastName()+doc1.getAddress()+doc1.getSpecialization);
				System.out.println(doc2.getIdentification()+doc2.getFirstName()+doc2.getLastName()+doc2.getAddress()+doc2.getSpecialization);
				System.out.println(doc3.getIdentification()+doc3.getFirstName()+doc3.getLastName()+doc3.getAddress()+doc3.getSpecialization);
				System.out.println(doc4.getIdentification()+doc4.getFirstName()+doc4.getLastName()+doc4.getAddress()+doc4.getSpecialization);
				break;
				
			case 3:
				break;
			
			case 4:
				break;
			
			case 5:
				break;
			}
		}
	}

public class Doctor 
{
	private String firstName;
	private String lastName;
	private String address;
	private String specialization;
	private int identification;
	
	public Doctor (int id, String fname, String lname, String add, String special)
	{
		firstName = fname;
		lastName = lname;
		address = add;
		specialization = special;
		identification = id;
	}
	
	public void setIdentification (int id)
	{
		identification = id;
	} 
	
	public int getIdentification ()
	{
		return identification;
	} 
	
	public void setFirstName (String fname)
	{
		firstName = fname;
	}
	
	public String getFirstName ()
	{
		return firstName;
	} 
	
	public void setLastName (String lname)
	{
		lastName = lname;
	} 
	
	public String getLastName ()
	{
		return lastName;
	} 
	
	public void setAddress (String add)
	{
		address = add;
	} 
	
	public String getAddress ()
	{
		return address;
	} 
	
	public void setPhoneNumber (int special)
	{
		specialization = special;
	} 
	
	public String getSpecialization ()
	{
		return specialization;
	} 
}

public class Patient 
{
	private String firstName;
	private String lastName;
	private String address;
	private int phoneNumber;
	private int identification;
	
	public Doctor (int id, String fname, String lname, String add, int phone)
	{
		firstName = fname;
		lastName = lname;
		address = add;
		phoneNumber = phone;
		identification = id;
	}
	
	public void setIdentification (int id)
	{
		identification = id;
	} 
	
	public int getIdentification ()
	{
		return identification;
	} 
	
	public void setFirstName (String fname)
	{
		firstName = fname;
	}
	
	public String getFirstName ()
	{
		return firstName;
	} 
	
	public void setLastName (String lname)
	{
		lastName = lname;
	} 
	
	public String getLastName ()
	{
		return lastName;
	} 
	
	public void setAddress (String add)
	{
		address = add;
	} 
	
	public String getAddress ()
	{
		return address;
	} 
	
	public void setPhoneNumber (int phone)
	{
		phoneNumber = phone;
	} 
	
	public int getPhoneNumber ()
	{
		return phoneNumber;
	} 
}

1 个答案:

答案 0 :(得分:0)

一种方法是将每个实例存储在ArrayList类型Class

例如:ArrayList<Patient> list = new ArrayList<>();

您知道有ArrayListPatient个对象。

并将它们全部添加为

list.add(pat1);
list.add(pat2);
list.add(pat3);

要删除它们,您只需调用remove()方法

即可
list.remove(pat2);

要编辑它们,您可以调用所需的特定对象,并使用Patient类中的set方法。

pat1.setFirstName("new name");

注意:您的构造函数参数与您尝试调用的内容不匹配,因此要么根据Patient类更改它们,要么更改Patient类构造函数。

此外,您的Patient构造函数为Doctor,但应为Patient。复制/粘贴存在问题。