Respuesta :
Answer:
Explanation:
//Code for this solution
//File: Person.java
import java.time.LocalDate;
//Person class
public class Person {
//Member variables
private String firstName;
private String lastName;
private LocalDate birthDate;
//Paramterized constructors that initializes all the member variables
public Person(String fName, String lName, LocalDate bDate) {
firstName = fName;
lastName = lName;
birthDate = bDate;
}
//Getter methods for each of the member variables
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public LocalDate getBirthDate() {
return birthDate;
}
}
//File: Couple.java
//Couple class
public class Couple {
//Member variables
private Person person1;
private Person person2;
//Paramterized constructors that initializes all the member variables
public Couple(Person p1, Person p2) {
person1 = p1;
person2 = p2;
}
//Getter methods for each of the member variables
public Person getFirstPerson() {
return person1;
}
public Person getSecondPerson() {
return person2;
}
}
//File: Wedding.java
import java.util.Date;
//Wedding class
public class Wedding {
//Member variables
private Date weddingDate;
private Couple couple;
private String location;
//Paramterized constructors that initializes all the member variables
public Wedding(Date date, Couple c, String wedLocation) {
weddingDate = date;
couple = c;
location = wedLocation;
}
//Getter methods for each of the member variables
public Date getWeddingDate() {
return weddingDate;
}
public Couple getCouple() {
return couple;
}
public String getLocation() {
return location;
}
}
//File: TestWedding.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
//Test driver class
public class TestWedding {
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//Method to display Wedding details - Couple, Location and Wedding date
public static void displayWedding(Wedding w) {
System.out.println("");
System.out.println("=== Wedding details ===");
Person p1 = w.getCouple().getFirstPerson();
Person p2 = w.getCouple().getSecondPerson();
System.out.println(p1.getFirstName() + " " + p2.getLastName() + "(born " + p1.getBirthDate().format(DateTimeFormatter.ISO_DATE) + ")"
+ " weds " + p2.getFirstName() + " " + p2.getLastName() + "(born " + p2.getBirthDate().format(DateTimeFormatter.ISO_DATE) + ")");
System.out.println("ON");
System.out.println( simpleDateFormat.format( w.getWeddingDate()));
System.out.println("AT");
System.out.println(w.getLocation());
}
//Test method - to create Person, Couple and Wedding objects
public static void main(String[] args) throws ParseException {
//Create Person objects
Person p10 = new Person("John", "Howard", LocalDate.of(2000, 10, 1));
Person p11 = new Person("Mary", "Eliza", LocalDate.of(2002, 1, 2));
//Create Couple object with above data
Couple c1 = new Couple(p10, p11);
//Create Wedding Object
Wedding w1 = new Wedding( simpleDateFormat.parse("2019-05-06"), c1, "CountrySide");
//Display Wedding details
displayWedding(w1);
Person p20 = new Person("James", "Howler", LocalDate.of(1999, 5, 1));
Person p21 = new Person("Jenny", "Hertz", LocalDate.of(2005, 4, 25));
Couple c2 = new Couple(p20, p21);
Wedding w2 = new Wedding(simpleDateFormat.parse("2019-10-02"), c2, "Mary Islands");
displayWedding(w2);
}
}
In this exercise we have to use the knowledge of computational language in JAVA to write the code.
This code can be found in the attached image.
To make it simpler the code is described as:
import java.time.LocalDate;
public class Person {
private String firstName;
private String lastName;
private LocalDate birthDate;
public Person(String fName, String lName, LocalDate bDate) {
firstName = fName;
lastName = lName;
birthDate = bDate;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public LocalDate getBirthDate() {
return birthDate;
}
}
public class Couple {
private Person person1;
private Person person2;
public Couple(Person p1, Person p2) {
person1 = p1;
person2 = p2;
}
public Person getFirstPerson() {
return person1;
}
public Person getSecondPerson() {
return person2;
}
}
import java.util.Date;
public class Wedding {
private Date weddingDate;
private Couple couple;
private String location;
public Wedding(Date date, Couple c, String wedLocation) {
weddingDate = date;
couple = c;
location = wedLocation;
}
public Date getWeddingDate() {
return weddingDate;
}
public Couple getCouple() {
return couple;
}
public String getLocation() {
return location;
}
}
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class TestWedding {
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
public static void displayWedding(Wedding w) {
System.out.println("");
System.out.println("=== Wedding details ===");
Person p1 = w.getCouple().getFirstPerson();
Person p2 = w.getCouple().getSecondPerson();
System.out.println(p1.getFirstName() + " " + p2.getLastName() + "(born " + p1.getBirthDate().format(DateTimeFormatter.ISO_DATE) + ")"
+ " weds " + p2.getFirstName() + " " + p2.getLastName() + "(born " + p2.getBirthDate().format(DateTimeFormatter.ISO_DATE) + ")");
System.out.println("ON");
System.out.println( simpleDateFormat.format( w.getWeddingDate()));
System.out.println("AT");
System.out.println(w.getLocation());
}
public static void main(String[] args) throws ParseException {
Person p10 = new Person("John", "Howard", LocalDate.of(2000, 10, 1));
Person p11 = new Person("Mary", "Eliza", LocalDate.of(2002, 1, 2));
Couple c1 = new Couple(p10, p11);
Wedding w1 = new Wedding( simpleDateFormat.parse("2019-05-06"), c1, "CountrySide");
displayWedding(w1);
Person p20 = new Person("James", "Howler", LocalDate.of(1999, 5, 1));
Person p21 = new Person("Jenny", "Hertz", LocalDate.of(2005, 4, 25));
Couple c2 = new Couple(p20, p21);
Wedding w2 = new Wedding(simpleDateFormat.parse("2019-10-02"), c2, "Mary Islands");
displayWedding(w2);
}
}
See more about JAVA at brainly.com/question/6490447

