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> patientName = new ArrayList<>();
- ArrayList<String> patientGender = new ArrayList<>();
- ArrayList<String> roomList = new ArrayList<>();
- void MainMenu() {
- System.out.println("=== BJ HOSPITAL ===");
- System.out.println("1. Add Patient");
- System.out.println("2. Remove Patient");
- System.out.println("3. Update Patient");
- System.out.println("4. View Patient");
- System.out.println("5. Exit");
- }
- private void AddPatient() {
- String name;
- String gender;
- String room;
- //nama nich
- do {
- System.out.print("Input your name[starts with Mr. and Mrs.]: ");
- name = scan.nextLine();
- }while(!name.startsWith("Mr.") && !name.startsWith("Mrs."));
- //gender nich
- do {
- System.out.print("Input your gender: ");
- gender = scan.nextLine();
- }while(!gender.equalsIgnoreCase("Male") && !gender.equalsIgnoreCase("Female"));
- //tipe kamar nich
- do {
- System.out.print("Choose your room[VIP/Regular]: ");
- room = scan.nextLine();
- }while(!room.equals("VIP") && !room.equals("Regular"));
- patientName.add(name);
- patientGender.add(gender);
- roomList.add(room);
- System.out.println("Success Add Patient");
- }
- private void ViewPatient() {
- if(patientName.isEmpty()) {
- System.out.println("There is no data of patient");
- }else {
- //biar bisa display semua nya pake looping cihuy
- int i = 0;
- System.out.println("No. | Name | Gender | Room Type");
- while(i < patientName.size()) {
- System.out.println((i+1) + "|" + patientName.get(i) + "|" + patientGender.get(i) + "|" + roomList.get(i));
- i++;
- }
- }
- }
- private void RemovePatient() {
- if(patientName.isEmpty()) {
- System.out.println("There is no data of patient");
- }else {
- int index = -1;
- ViewPatient();
- do {
- System.out.print("Input number you want to delete: ");
- try {
- index = scan.nextInt();
- }catch(Exception e) {
- index = -1;
- }
- scan.nextLine();
- //-1 biar ke hapus sesuai sama yg dipengenin
- index = index - 1;
- }while(index < 0 || index > patientName.size() -1);
- patientName.remove(index);
- patientGender.remove(index);
- roomList.remove(index);
- System.out.println("Success Remove Patient");
- }
- }
- private void UpdatePatient() {
- if(patientName.isEmpty()) {
- System.out.println("There is no data of patient");
- }else {
- int index = -1;
- ViewPatient();
- do {
- System.out.print("Input number you want to update: ");
- try {
- index = scan.nextInt();
- }catch(Exception e) {
- index = -1;
- }
- scan.nextLine();
- index = index - 1;
- }while(index < 0 || index > patientName.size() -1);
- String name;
- String gender;
- String room;
- do {
- System.out.print("Input your name[starts with Mr. and Mrs.]: ");
- name = scan.nextLine();
- }while(!name.startsWith("Mr.") && !name.startsWith("Mrs."));
- do {
- System.out.print("Input your gender: ");
- gender = scan.nextLine();
- }while(!gender.equalsIgnoreCase("Male") && !gender.equalsIgnoreCase("Female"));
- do {
- System.out.print("Choose your room[VIP/Regular]: ");
- room = scan.nextLine();
- }while(!room.equals("VIP") && !room.equals("Regular"));
- patientName.set(index, name);
- patientGender.set(index, gender);
- roomList.set(index, name);
- System.out.println("Success Update Patient");
- }
- }
- public Main() {
- // TODO Auto-generated constructor stub
- int choose;
- do {
- MainMenu();
- System.out.print(">> ");
- try {
- choose = scan.nextInt();
- }catch(Exception e) {
- choose = -1;
- }
- scan.nextLine();
- if(choose == 1) {
- AddPatient();
- }else if(choose == 2) {
- RemovePatient();
- }else if(choose == 3) {
- UpdatePatient();
- }else if(choose == 4) {
- ViewPatient();
- }
- }while(choose != 5);
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- new Main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement