Write a java class called Event.java representing an event set up in someone\'s
ID: 3797604 • Letter: W
Question
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 Write a java applicatExplanation / Answer
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.Scanner;
class Event {
private String title;
private String Venue;
private GregorianCalendar date;
private Double duration;
// gets Title
public String getTitle() {
return title;
}
//sets title
public void setTitle(String title) {
this.title = title;
}
//gets Venue
public String getVenue() {
return Venue;
}
//sets Venue
public void setVenue(String venue) {
Venue = venue;
}
//gets date
public GregorianCalendar getDate() {
return date;
}
//sets date
public void setDate(GregorianCalendar date) {
this.date = date;
}
//gets duration
public Double getDuration() {
return duration;
}
//sets duration
public void setDuration(Double duration) {
this.duration = duration;
}
}
public class EventTest{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
Event first = new Event();
Event second = new Event();
//getting 1st event details
System.out.println("Enter Title of the first Event");
String firstEventTitle=scan.nextLine();
System.out.println("Enter venue of the first Event");
String firstEventVenue=scan.nextLine();
System.out.println("Enter date of the first Event(MM/dd/yyyy)");
String firstEventDate=scan.nextLine();
String arr[]=firstEventDate.split("/");
int year = Integer.parseInt(arr[2]);
int month = Integer.parseInt(arr[0]);
int day = Integer.parseInt(arr[1]);
GregorianCalendar firstEvent = new GregorianCalendar(year, month, day);
System.out.println("Enter duration of the first Event");
Double firstEventDuration=scan.nextDouble();
scan.nextLine();// to read the next line after getting the double
//getting second event details
System.out.println("Enter Title of the Second Event");
String secondEventTitle=scan.nextLine();
System.out.println("Enter venue of the Second Event");
String secondEventVenue=scan.nextLine();
System.out.println("Enter date of the Second Event(MM/dd/yyyy)");
String secondEventDate=scan.nextLine();
String arr1[]=secondEventDate.split("/");
int year1 = Integer.parseInt(arr1[2]);
int month1 = Integer.parseInt(arr1[0]);
int day1 = Integer.parseInt(arr1[1]);
GregorianCalendar secondEvent = new GregorianCalendar(year1, month1, day1);
System.out.println("Enter duration of the Second Event");
Double secondEventDuration=scan.nextDouble();
//setting it to the first event object
first.setTitle(firstEventTitle);
first.setVenue(firstEventVenue);
first.setDate(firstEvent);
first.setDuration(firstEventDuration);
//setting it to the first event object
second.setTitle(secondEventTitle);
second.setVenue(secondEventVenue);
second.setDate(secondEvent);
second.setDuration(secondEventDuration);
//printing the value with the help of a function
System.out.println("FirstEvent details ");
printDetails(first);
System.out.println("SecondEvent details ");
printDetails(second);
scan.close();
}
//method to print the details
private static void printDetails(Event e) {
System.out.println("Event Title: "+e.getTitle());
System.out.println("Event Venue: "+e.getVenue());
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");// for pretty printing of date
String date=format.format(e.getDate().getTime());
System.out.println("Event Date: "+date);
System.out.println("Event Duration: "+e.getDuration());
}
}
/output/
Enter Title of the first Event
New Student Welcome
Enter venue of the first Event
Student Union Building
Enter date of the first Event(MM/dd/yyyy)
02/22/2017
Enter duration of the first Event
4
Enter Title of the Second Event
Big Data Session
Enter venue of the Second Event
Academic Building
Enter date of the Second Event(MM/dd/yyyy)
02/21/2017
Enter duration of the Second Event
2
FirstEvent details
Event Title: New Student Welcome
Event Venue: Student Union Building
Event Date: 03/22/2017
Event Duration: 4.0
SecondEvent details
Event Title: Big Data Session
Event Venue: Academic Building
Event Date: 03/21/2017
Event Duration: 2.0
/output/
Note: Feel free to ask question/doubts. God bless you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.