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

1- Write a java class called Event.java representing an event set up in someone’

ID: 3797583 • Letter: 1

Question

1- Write a java class called Event.java representing an event set up in someone’s calendar. This class should store three bits of information about the event:

What is the title of the event (a String)
Where is the event going to take place (a String)
What is the date the event is going to take place (a GregorianCalendar)

How many hours long is the event (a Double) The Event class should have eight methods

setTitle(String title) for setting and storing the title of the event

String getTitle() for returning the title of the event

setVenue(String venue) for setting and storing the venue of the event

String getVenue() for returning the venue of the event

setDate(GregorianCalendar date) for setting and storing the date of the event

String getDate() for returning the date of the event in MM/dd/yyyy

setDuration(double duration) for setting and storing the duration in hours of the event

double getDuration() for returning the length of the event in hours

2. Write a java application called EventTest.java that lets the user create two Event objects and then prints the following sample output.

Enter title of the first event: New Student Welcome
Enter venue of the first event: Student Union Building
Enter the date of the first event (MM/dd/yyyy): 02/22/2017

Enter duration for first event: 2.5
Enter title of the second event: Job Fair
Enter venue of the second event: University Career Center

Enter the date of the second event (MM/dd/yyyy): 02/15/2017

Enter duration for second event: 6

Output:

“Student Orientation” event will take place on 02/22/2017 for 2.5 hours in Student Union Building
“Job Fair” event will take place on 07/26/2017 for 6 hours in University Career Center.

3- Rewrite your code and create a class date and use it (instead of using a GregorianCalendar), and test it again.

Explanation / Answer

EventTest.java

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.Scanner;


public class EventTest {

  
   public static void main(String[] args) throws ParseException {
       Scanner scan = new Scanner(System.in);
       System.out.print("Enter title of the first event: ");
       String title1 = scan.nextLine();
       System.out.print("Enter venue of the first event: ");
       String venue1 = scan.nextLine();
       System.out.print("Enter the date of the first event (MM/dd/yyyy): ");
       String dateStr1 = scan.next();
       DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
       java.util.Date parsed1 = df.parse(dateStr1);
       GregorianCalendar date1 = new GregorianCalendar();
       date1.setTime(parsed1);
       System.out.print("Enter duration for first event: ");
       double duration1 = scan.nextDouble();
       scan.nextLine();
       System.out.print("Enter title of the second event: ");
       String title2 = scan.nextLine();
       System.out.print("Enter venue of the second event: ");
       String venue2 = scan.nextLine();
       System.out.print("Enter the date of the second event (MM/dd/yyyy): ");
       String dateStr2 = scan.next();
       java.util.Date parsed2 = df.parse(dateStr2);
       GregorianCalendar date2 = new GregorianCalendar();
       date2.setTime(parsed2);
       System.out.print("Enter duration for second event: ");
       double duration2 = scan.nextDouble();
       Event event1 = new Event();
       event1.setVenue(venue1);
       event1.setTitle(title1);
       event1.setDuration(duration1);
       event1.setDate(date1);
       Event event2 = new Event();
       event2.setVenue(venue2);
       event2.setTitle(title2);
       event2.setDuration(duration2);
       event2.setDate(date2);
       System.out.println("""+event1.getTitle()+"" event will take place on "+df.format(event1.getDate().getTime())+" hours in "+event1.getVenue());
       System.out.println("""+event2.getTitle()+"" event will take place on "+df.format(event2.getDate().getTime())+" for "+event2.getDuration()+" hours in "+event2.getVenue());
   }

}

Event.java

import java.util.GregorianCalendar;


public class Event {
   private String title;
   private String venue;
   private GregorianCalendar date;
   private double duration;
   public Event(){
      
  
   }
   public String getTitle() {
       return title;
   }
   public void setTitle(String title) {
       this.title = title;
   }
   public String getVenue() {
       return venue;
   }
   public void setVenue(String venue) {
       this.venue = venue;
   }
   public GregorianCalendar getDate() {
       return date;
   }
   public void setDate(GregorianCalendar date) {
       this.date = date;
   }
   public double getDuration() {
       return duration;
   }
   public void setDuration(double duration) {
       this.duration = duration;
   }
  
}

Output:

Enter title of the first event: Student Orientation
Enter venue of the first event: Student Union Building
Enter the date of the first event (MM/dd/yyyy): 02/22/2017
Enter duration for first event: 2.5
Enter title of the second event: Job Fair
Enter venue of the second event: University Career Center
Enter the date of the second event (MM/dd/yyyy): 02/15/2017
Enter duration for second event: 6
"Student Orientation" event will take place on 02/22/2017 hours in Student Union Building
"Job Fair" event will take place on 02/15/2017 for 6.0 hours in University Career Center

3- Rewrite your code and create a class date and use it (instead of using a GregorianCalendar), and test it again.

EventTest.java

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;


public class EventTest {

  
   public static void main(String[] args) throws ParseException {
       Scanner scan = new Scanner(System.in);
       System.out.print("Enter title of the first event: ");
       String title1 = scan.nextLine();
       System.out.print("Enter venue of the first event: ");
       String venue1 = scan.nextLine();
       System.out.print("Enter the date of the first event (MM/dd/yyyy): ");
       String dateStr1 = scan.next();
       DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
       java.util.Date parsed1 = df.parse(dateStr1);
      
       System.out.print("Enter duration for first event: ");
       double duration1 = scan.nextDouble();
       scan.nextLine();
       System.out.print("Enter title of the second event: ");
       String title2 = scan.nextLine();
       System.out.print("Enter venue of the second event: ");
       String venue2 = scan.nextLine();
       System.out.print("Enter the date of the second event (MM/dd/yyyy): ");
       String dateStr2 = scan.next();
       java.util.Date parsed2 = df.parse(dateStr2);
       System.out.print("Enter duration for second event: ");
       double duration2 = scan.nextDouble();
       Event event1 = new Event();
       event1.setVenue(venue1);
       event1.setTitle(title1);
       event1.setDuration(duration1);
       event1.setDate(parsed1);
       Event event2 = new Event();
       event2.setVenue(venue2);
       event2.setTitle(title2);
       event2.setDuration(duration2);
       event2.setDate(parsed2);
       System.out.println("""+event1.getTitle()+"" event will take place on "+df.format(event1.getDate().getTime())+" hours in "+event1.getVenue());
       System.out.println("""+event2.getTitle()+"" event will take place on "+df.format(event2.getDate().getTime())+" for "+event2.getDuration()+" hours in "+event2.getVenue());
   }

}

Event.java

import java.util.Date;
import java.util.GregorianCalendar;


public class Event {
   private String title;
   private String venue;
   private Date date;
   private double duration;
   public Event(){
      
  
   }
   public String getTitle() {
       return title;
   }
   public void setTitle(String title) {
       this.title = title;
   }
   public String getVenue() {
       return venue;
   }
   public void setVenue(String venue) {
       this.venue = venue;
   }
   public Date getDate() {
       return date;
   }
   public void setDate(Date date) {
       this.date = date;
   }
   public double getDuration() {
       return duration;
   }
   public void setDuration(double duration) {
       this.duration = duration;
   }
  
}

Output:

Enter title of the first event: Student Orientation
Enter venue of the first event: Student Union Building
Enter the date of the first event (MM/dd/yyyy): 02/22/2017
Enter duration for first event: 2.5
Enter title of the second event: Job Fair
Enter venue of the second event: University Career Center
Enter the date of the second event (MM/dd/yyyy): 02/15/2017
Enter duration for second event: 6
"Student Orientation" event will take place on 02/22/2017 hours in Student Union Building
"Job Fair" event will take place on 02/15/2017 for 6.0 hours in University Career Center