Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Main {
- Scanner scan = new Scanner(System.in);
- ArrayList<String> nameList = new ArrayList<>();
- ArrayList<String> genderList = new ArrayList<>();
- ArrayList<String> roomTypeList = new ArrayList<>();
- void PrintMenu(){
- System.out.println("BJ Hospital");
- System.out.println("1. Add Patient");
- System.out.println("2. View Patient");
- System.out.println("3. Exit");
- System.out.println("4. Update Patient");
- System.out.println("5. Delete Patient");
- System.out.print("Choose >> ");
- }
- public Main() {
- // TODO Auto-generated constructor stub
- int choose;
- do{
- PrintMenu();
- try {
- choose = scan.nextInt();
- } catch (Exception e) {
- // TODO: handle exception
- choose = -1;
- }
- scan.nextLine();
- if(choose == 1){
- AddPatient();
- }else if(choose == 2){
- ViewPatient();
- }else if(choose == 4){
- UpdatePatient();
- }else if(choose == 5){
- DeletePatient();
- }
- }while(choose != 3);
- }
- private void DeletePatient() {
- // TODO Auto-generated method stub
- int index = -1;
- ViewPatient();
- do
- {
- System.out.println("Input index to Delete : ");
- try {
- index = scan.nextInt();
- } catch (Exception e) {
- // TODO: handle exception
- index = -1;
- }
- scan.nextLine();
- //karna pas di view dimulai dari 1 ...
- index = index - 1;
- }while(index<0 || index > nameList.size()-1);
- nameList.remove(index);
- genderList.remove(index);
- roomTypeList.remove(index);
- }
- private void UpdatePatient() {
- // TODO Auto-generated method stub
- int index = -1;
- ViewPatient();
- do
- {
- System.out.println("Input index to Update : ");
- try {
- index = scan.nextInt();
- } catch (Exception e) {
- // TODO: handle exception
- index = -1;
- }
- scan.nextLine();
- //karna pas di view dimulai dari 1 ...
- index = index - 1;
- }while(index<0 || index > nameList.size()-1);
- String name;
- String gender;
- String roomType;
- do
- {
- System.out.print("Input your name [starts with 'Mr.' or 'Mrs.']: ");
- name = scan.nextLine();
- }while(!name.startsWith("Mr.") && !name.startsWith("Mrs."));
- do
- {
- System.out.print("Input your gender ['Male' or 'Female'[Case Insensitive]]: ");
- gender = scan.nextLine();
- }while(!gender.equalsIgnoreCase("Male") && !gender.equalsIgnoreCase("Female"));
- do
- {
- System.out.print("Choose your room type ['VIP' or 'Normal']: ");
- roomType = scan.nextLine();
- }while(!roomType.equals("VIP") && !roomType.equals("Normal"));
- nameList.set(index, name);
- genderList.set(index, gender);
- roomTypeList.set(index, roomType);
- }
- private void ViewPatient() {
- // TODO Auto-generated method stub
- if(nameList.isEmpty())
- {
- System.out.println("No Patient!");
- }else
- {
- //looping semua di nameList / semua patient
- System.out.println("No. | Name | Gender | RoomType");
- for(int i=0; i<nameList.size();i++)
- {
- System.out.println((i+1)+" | "+nameList.get(i)+" | "+genderList.get(i)+" | "+roomTypeList.get(i));
- }
- }
- }
- private void AddPatient() {
- // TODO Auto-generated method stub
- String name;
- String gender;
- String roomType;
- do
- {
- System.out.print("Input your name [starts with 'Mr.' or 'Mrs.']: ");
- name = scan.nextLine();
- }while(!name.startsWith("Mr.") && !name.startsWith("Mrs."));
- do
- {
- System.out.print("Input your gender ['Male' or 'Female'[Case Insensitive]]: ");
- gender = scan.nextLine();
- }while(!gender.equalsIgnoreCase("Male") && !gender.equalsIgnoreCase("Female"));
- do
- {
- System.out.print("Choose your room type ['VIP' or 'Normal']: ");
- roomType = scan.nextLine();
- }while(!roomType.equals("VIP") && !roomType.equals("Normal"));
- nameList.add(name);
- genderList.add(gender);
- roomTypeList.add(roomType);
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- new Main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement