0% found this document useful (0 votes)
25 views3 pages

Appointment Scheduler

This document contains code for an appointment scheduling application for a beauty salon. The application allows scheduling up to 10 appointments per day, with 3 morning slots between 8-12am and 7 afternoon slots between 12-6pm. It checks for available slots, displays scheduled appointments, and confirms when an appointment is taken after processing. It also provides a 30% discount message for appointments on January 1st.

Uploaded by

Ben 10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Appointment Scheduler

This document contains code for an appointment scheduling application for a beauty salon. The application allows scheduling up to 10 appointments per day, with 3 morning slots between 8-12am and 7 afternoon slots between 12-6pm. It checks for available slots, displays scheduled appointments, and confirms when an appointment is taken after processing. It also provides a 30% discount message for appointments on January 1st.

Uploaded by

Ben 10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

package com.java.

Hand_On_Projects;

import java.util.ArrayList;
import java.util.Scanner;

/*
You Have Been given a task to create Appointment Scheduler application for
beauty saloon. The application should accept date and time to schedule appointment.
The application can only take 10 appointments each day 3 in morning 7 in
afternoon(>= 12:00 and < 18:00).
the application should tell me if appointment is taken or not.
If appointment is made on 1st Jan Wish customer happy new year with 30% discount
message.
*/
class Details{
protected String date,time;
Details(String date,String time){
this.date=date;
this.time=time;
}

@Override
public boolean equals(Object obj){
if(this==obj){
return true;
}
if(obj==null|| getClass() != obj.getClass()){
return false;
}
Details ob = (Details) obj;
return this.date.equals(ob.date) && this.time.equals(ob.time);
}
@Override
public String toString(){
return this.date + " " + this.time;
}

class Appointment{
protected ArrayList<Details> list = new ArrayList<>();
int nm=3,ne=7;

public void morning(String date,String time) throws NumberFormatException{


if(nm>0){
int t = Integer.parseInt(time);
if((t>=8 && t<12)){
Details obj = new Details(date,time);
list.add(obj);
nm--;
check(date);
} else {
System.out.println("Timings must be between 8:00 AM and 12:00 AM");
System.out.println();
}
} else {
System.out.println("Appointments in Morning has been completed, please
take Appointment in Evening...");
evening(date,time);
System.out.println();
}
}
public void check(String d){
if(d.equals("1stJan")){
System.out.println("Happy New Year, you have got 30% discount");
}
}
public void evening(String date,String time) throws NumberFormatException{
if(ne>0){
int t = Integer.parseInt(time);
if((t>=12 && t<18)){
Details obj = new Details(date,time);
list.add(obj);
ne--;
check(date);
} else {
System.out.println("Timings must be between 12:00 PM and 18:00
PM");
System.out.println();
}
} else {
System.out.println("Appointments in Evening has been completed, please
visit Tomorrow...");
System.out.println();
}
}

public void showAppointments(){


System.out.println("Date Time:");
if(!list.isEmpty()){
for(Details list: list){
System.out.println(list);
}
System.out.println();
} else {
System.out.println("No Appointments yet added");
System.out.println();
}
}

public void AppointmentTaken(String date,String time) throws


InterruptedException{
Details obj = new Details(date,time);
if(list.contains(obj)){
System.out.println("Appointment not taken,Take Appointment");
System.out.println("Please wait..!!");
String s = "Appointment is under process...";
for(int i=0;i<s.length();i++){
System.out.print(s.charAt(i));
Thread.sleep(120);
}
System.out.println("Appointment taken");
list.remove(obj);
} else {
System.out.println("Not in the list");
}
}
public void noOfMorningAppointments(){
System.out.println("Number of Appointments left in Morning: " + nm);
}

public void noOfEveningAppointments(){


System.out.println("Number of Appointments left in Evening: " + ne);
System.out.println();
}

public class Appointment_Scheduler {


public static void main(String[] args) throws InterruptedException{
Appointment d = new Appointment();
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("***Appointment Scheduler***\n1.Appointment_Morning\
n2.Appointment_Evening\n3.Number of Appointments\n4.Details of Appointment\
n5.Appointments Taken\n6.Exit\nEnter your Option: ");
int n=sc.nextInt();
switch(n){
case 1 -> {
System.out.println("Enter date and time: ");
d.morning(sc.next(),sc.next());
}
case 2 -> {
System.out.println("Enter date and time: ");
d.evening(sc.next(),sc.next());
}
case 3 -> {
d.noOfMorningAppointments();
d.noOfEveningAppointments();
}
case 4 -> d.showAppointments();
case 5 -> d.AppointmentTaken(sc.next(),sc.next());
case 6 -> System.exit(0);
default -> System.out.println("Invalid Option");
}
}
}
}

You might also like