/* 회원관리 프로그램 (회원정보 입력, 검색, 수정, 삭제, 프로그램 종료 기능) */
Member.java
public class Member
{
String name;
String sex;
int age;
String phone;
String email;
public Member(String name, String sex, int age, String phone, String email)
{
this.name = name;
this.sex = sex;
this.age = age;
this.phone = phone;
this.email = email;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getSex()
{
return sex;
}
public void setSex(String sex)
{
this.sex = sex;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
}
VectorTest3.java
import java.util.Scanner;
import java.util.Vector;
public class VectorTest3
{
public static void main(String args[])
{
Vector<Member> vm = new Vector<>();
while(true)
{
System.out.println("1.입력 2.검색 3.수정 4.삭제 5.종료");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
if(choice==1)
{
System.out.print("name : ");
String name = sc.next();
System.out.print("sex : ");
String sex = sc.next();
System.out.print("age : ");
int age = sc.nextInt();
System.out.print("phone number : ");
String phone = sc.next();
System.out.print("email : ");
String email = sc.next();
vm.add( new Member(name, sex, age, phone, email) );
for(int i=0; i<vm.size(); i++)
System.out.println("member : "
+vm.get(i).getName()+" "
+vm.get(i).getSex()+" "
+vm.get(i).getAge()+" "
+vm.get(i).getPhone()+" "
+vm.get(i).getEmail());
}
else if(choice==2)
{
System.out.print("name : ");
String name = sc.next();
System.out.println(vm.size());
for(int i=0; i<vm.size(); i++)
{
System.out.println("Searching...");
if(name.equals(vm.get(i).getName()))
{
System.out.println(vm.get(i).getName()+" "
+vm.get(i).getSex()+" "
+vm.get(i).getAge()+" "
+vm.get(i).getPhone()+" "
+vm.get(i).getEmail());
break;
}
else
System.out.println("Not Exist!");
}
}
else if(choice==3)
{
System.out.print("name : ");
String name = sc.next();
for(int i=0; i<vm.size(); i++)
{
if(name.equals(vm.get(i).getName()))
{
int age;
String phone;
System.out.print("age : ");
age = sc.nextInt();
System.out.print("phone : ");
phone = sc.next();
vm.get(i).setAge(age);
vm.get(i).setPhone(phone);
}
else
System.out.println("Not Exist!");
}
}
else if(choice==4)
{
System.out.print("name : ");
String name = sc.next();
for(int i=0; i<vm.size(); i++)
{
if(name.equals(vm.get(i).getName()))
{
System.out.println("Deleting...");
vm.remove(i);
}
}
}
else if(choice==5)
{
System.out.println("Shutdown");
break;
}
}
}
}
댓글 없음:
댓글 쓰기