Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sequence Diagrams 1. Schedule an appointment The scenario begins when the user c

ID: 3692245 • Letter: S

Question

Sequence Diagrams

1. Schedule an appointment

The scenario begins when the user chooses to add a new appointment in the UI. The UI notices which part of the calendar is active and pops up an Add Appointment window for that date and time. The user enters information about the appointment's name, location, start and end times. The UI will prevent the user from entering an appointment that has invalid information, such as an empty name or negative duration. The calendar records the new appointment in the user's list of appointments. Any reminder selected by the user is added to the list of reminders. If the user already has an appointment at that time, the user is shown a message and asked to choose an available time or replace the appointment. If the user enters an appointment with the same name and duration as an existing meeting, the calendar asks the user whether he/she intended to join that meeting instead. If so, the user is added to that meeting's list of participants.

20

The user clicks on return on UI that displays a list of items purchased in the past (Remember there is an implicit grouping by order but that's an abstraction that the user doesn't need to know) . The user then chooses the item(s) to return. A feedback screen is shown to enter why the return is being made. Upon entering the details, the item is marked as returned and a refund is initiated to the same payment type that was used in the order. A confirmation page is shown to the user.

Explanation / Answer

Please follow the Code and comments for the description :

Though the given problem and the solution may slightly differ at times, hope this matches the requirement.

CODE :

package com.appointmentsys;

import javax.swing.JFrame;
import java.util.GregorianCalendar;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


/**
*
* @author anonymous
*
*/
public class ControllerGUI extends JPanel {

    static JButton button1;
    static JButton button2;
    static JButton button3;
    static JButton button4;
    static JTextField ta;

    static AppointmentBook appBook = new AppointmentBook();
    static EventHandler eventHandler;

    public static void CreateandShowGUI() {

        JFrame frame = new JFrame();
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(10, 10));

        button1 = new JButton("Add appointment");
        button2 = new JButton("Remove appointment");
        button3 = new JButton("Show appointment");
        ta = new JTextField();
        button4 = new JButton("Search appointments");

        eventHandler = new EventHandler();
        button1.addActionListener(eventHandler);
        button2.addActionListener(eventHandler);
        button3.addActionListener(eventHandler);
        button4.addActionListener(eventHandler);

        frame.setContentPane(panel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);

        panel.add(new JLabel("         "));
        panel.add(new JLabel("Please select an option: "));
        panel.add(new JLabel("         "));
        panel.add(button1);
        panel.add(button2);
        panel.add(button3);
        panel.add(button4);
        panel.add(ta);
        panel.setBorder(BorderFactory.createTitledBorder("Appointment System"));

    }
public class EventHandler implements ActionListener{


        public void actionPerformed(ActionEvent e){
            if(e.getSource() == button1){
            appBook.add(new Appointment(new GregorianCalendar(2015, 8+1, 14, 10, 30 ), new GregorianCalendar(2015, 10, 14, 11, 30), "Anonymous"));
            }
            else if(e.getSource() == button3){
                String appointmentInfo = appBook.getAppointment(0).toString();
                ta2.setText(appointmentInfo);

            }

        }
}

    public static void main(String[] args) {

        javax.swing.SwingUtilities.invokeLater(new Runnable(){
    public void run(){
        CreateandShowGUI();
        }
            });
        }


    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub

    }


}

package com.appointmentsys;

import java.util.ArrayList;
import java.util.GregorianCalendar;

/**
*
* Controller class will test Appointment/AppointmentBook
* @author Anonymous
*
*/
public class Controller {

    public static void main(String[] args) {

        Appointment a1 = new Appointment(new GregorianCalendar(2015, 8+1, 14, 10, 30 ), new GregorianCalendar(2015, 10, 14, 11, 30), "abc");
        Appointment a2 = new Appointment(new GregorianCalendar(2015, 8+1, 20, 9, 00), new GregorianCalendar(2015, 10, 20, 10, 10), "XYZ");
        Appointment a3 = new Appointment(new GregorianCalendar(2015, 8+1, 21, 14, 00), new GregorianCalendar(2015, 10, 21, 16, 00), "ABCD");             
        Appointment a4 = new Appointment(new GregorianCalendar(2015, 8+1, 21, 14, 00), new GregorianCalendar(2015, 10, 21, 16, 00), "PQR");

        AppointmentBook appBook = new AppointmentBook();
        appBook.add(a1);
        appBook.add(a2);
        appBook.add(a3);
        appBook.add(a4);

        System.out.println("Appointment is in book: " + appBook.isInBook(a1));
        System.out.println("Appointment is in book: " + appBook.isInBook(a4));
        //appBook.remove(a1);
        appBook.ShowAppointments();


    }
}

    package com.appointmentsys;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;


public class Appointment {

    //Appointments have start/end times & dates.
    //Every appointment has a title.

    private GregorianCalendar startDateTime;
    private GregorianCalendar endDateTime;
    private String eventTitle;

    //default constructor
    public Appointment(){
        this.startDateTime = null;
        this.endDateTime = null;
        this.eventTitle = "";
    }

    //constructor

    public Appointment(GregorianCalendar startDate, GregorianCalendar endDate, String eventTitle){
        this.startDateTime = startDate;
        this.endDateTime = endDate;
        this.eventTitle = eventTitle;
    }


    public GregorianCalendar getStartDateTime() {
        return startDateTime;
    }
    public void setStartDateTime(GregorianCalendar startDateTime) {
        this.startDateTime = startDateTime;
    }
    public GregorianCalendar getEndDateTime() {
        return endDateTime;
    }
    public void setEndDateTime(GregorianCalendar endDateTime) {
        this.endDateTime = endDateTime;
    }
    public String getEventTitle() {
        return eventTitle;
    }
    public void setEventTitle(String eventTitle) {
        this.eventTitle = eventTitle;
    }

    //toString() method to represent an appointment object
    public String toString(){

        String strdate = null;
        int hours = 0;
        String hrs = null;
        int mins = 0;
        String min = null;

        SimpleDateFormat sdf = new SimpleDateFormat("MM/DD/YYYY");

        if (getStartDateTime() != null ){
            strdate = sdf.format(getStartDateTime().getTime());
            hours = getStartDateTime().get(Calendar.HOUR);
            hrs = Integer.toString(hours);
            mins = getStartDateTime().get(Calendar.MINUTE);
            min = Integer.toString(mins);
        }
        String s = getEventTitle()+" "+ strdate+" "+ hrs +": "+min;
        return "Appointment: " + s;

    }


}

    package com.appointmentsys;

import java.util.ArrayList;

public class AppointmentBook {

    private static final int NOTFOUND = -1; //NOTFOUND int constant

    //We can use an ArrayList to store appointments (you could use a database)

    private ArrayList<Appointment> appointmentList = new ArrayList<Appointment>();

    //add method to appointmentbook

    /**
     * Adds appointments to the appointmentList
     * @param a
     */

    public void add(Appointment a ){

    appointmentList.add(a);
    }
    /**
     * create a new arrayList for all appoints then return all
     * @return
     */

    public ArrayList<Appointment> getAllAppointments(){

        ArrayList<Appointment> all = new ArrayList<Appointment>(appointmentList);
        return all;
    }
    /**
     * Prints out the list of all the appointsment made
     *
     */
    public void ShowAppointments()
    {
        ArrayList<Appointment> all = new ArrayList<Appointment>(appointmentList);
        System.out.println();
        System.out.print("All appointments: ");


        for(Appointment a: all)
        {
            System.out.println(a);
            System.out.println();
        }
    }
    /**
     * returns -1 if no appointment is found
     * @param tofind
     * @return
     */
    private int find(Appointment tofind)
    {
        int i = 0;

        for(Appointment a: appointmentList)
        {
            if(a.equals(tofind)) return i;
            i++;
        }
                return NOTFOUND;
    }
    /**
     * removes an appointment from the appointmentList
     * @param toRemove
     */
    public void remove(Appointment toRemove){

        int location = find(toRemove);
        if(location != NOTFOUND) appointmentList.remove(location);
        else
            throw new IllegalArgumentException("Appointment not found");
    }
    /**
     *
     * @param a
     * @return
     */
    public boolean isInBook(Appointment a){
        return find(a) != NOTFOUND;

    }

    public String getAppointment(int i) {

        return appointmentList.get(i).toString();

    }

}

Hope this is helpful.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote