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

Instructions Expand the wedding class to include six weddings. Submit your heavi

ID: 3709424 • Letter: I

Question


Instructions

Expand the wedding class to include six weddings. Submit your heavily commented code and a test run of all six weddings. Describe the programming strategy you used and cite sources.

import java.time.*;public class TestWedding{public static void main(String[] args){LocalDate date1 = LocalDate.of(1986, 12, 14);LocalDate date2 = LocalDate.of(1984, 3, 8);LocalDate date3 = LocalDate.of(1991, 4, 17);LocalDate date4 = LocalDate.of(1992, 2, 14);LocalDate date5 = LocalDate.of(2016, 6, 18);LocalDate date6 = LocalDate.of(2016, 6, 25);Person bride1 = new Person("Kimberly", "Hanson", date1); // Create New personPerson groom1 = new Person("Mark", "Ziller", date2); // Create New personPerson bride2 = new Person("Janna", "Howard", date3); // Create New personPerson groom2 = new Person("Julius", "Nemo", date4); // Create New personCouple couple1 = new Couple(bride1, groom1); // Create New coupleCouple couple2 = new Couple(bride2, groom2); // Create New coupleWedding wedding1 = new Wedding(couple1, date5, "Mayfair Country Club");// create a wedding and send it couple1, date5 and a placeWedding wedding2 = new Wedding(couple2, date6, "Oceanview Park");// create a wedding and send it couple1, date5 and a placedisplayWeddingDetails(wedding1); // display wedding1 detailsdisplayWeddingDetails(wedding2); // display wedding2 details}public static void displayWeddingDetails(Wedding w){Couple couple = w.getCouple();LocalDate weddingDate = w.getWeddingDate();String location = w.getLocation();Person bride = couple.getBride();Person groom = couple.getGroom();String firstBride = bride.getFirstName();String lastBride = bride.getLastName();LocalDate brideBDate = bride.getBirthDate();String firstGroom = groom.getFirstName();String lastGroom = groom.getLastName();LocalDate groomBDate = groom.getBirthDate();System.out.println(" " + lastBride + "/" + lastGroom + " Wedding");System.out.println("Date: " + weddingDate + " Location: " +location);System.out.println("Bride: " + firstBride +" " + lastBride + " " + brideBDate);System.out.println("Groom: " + firstGroom +" " + lastGroom + " " + groomBDate);}}import java.time.*;public class Person{private String firstName;private String lastName;private LocalDate birthDate;public Person(String first, String last, LocalDate date){firstName = first;lastName = last;birthDate = date;}public String getFirstName(){return firstName;}public String getLastName(){return lastName;}public LocalDate getBirthDate(){return birthDate;}}import java.time.*;public class Couple{private Person bride;private Person groom;public Couple(Person br, Person gr) // couple contructor{bride = br;groom = gr;}public Person getBride(){return bride;}public Person getGroom(){return groom;}}import java.time.*;public class Wedding{private Couple couple;private LocalDate weddingDate;private String location;public Wedding(Couple c, LocalDate date, String loc) // wedding constructor{couple = c;weddingDate = date;location = loc;}public Couple getCouple(){return couple;}public LocalDate getWeddingDate(){return weddingDate;}public String getLocation(){return location;}}

Explanation / Answer

Since you needed 6 weedings, instead of rewriting same code, you could use Arrays. In the attached code, 6 weddings have been created and their details displayed.

I have created Arrays for bride names, groom names, couple details, and weddings. This has removed the need for writing the line to create new couples again and again, and also the line to display wedding details.

I hope this is what you wanted.

Code:

import java.time.*;

public class TestWedding {

   public static void main(String[] args) {

       // Creating dates
       LocalDate date1 = LocalDate.of(1986, 12, 14);
       LocalDate date2 = LocalDate.of(1984, 3, 8);
       LocalDate date3 = LocalDate.of(1991, 4, 17);
       LocalDate date4 = LocalDate.of(1992, 2, 14);
       LocalDate date5 = LocalDate.of(1988, 6, 18);
       LocalDate date6 = LocalDate.of(1988, 6, 25);
       LocalDate date7 = LocalDate.of(1990, 4, 20);
       LocalDate date8 = LocalDate.of(1992, 9, 21);
       LocalDate date9 = LocalDate.of(1991, 11, 6);
       LocalDate date10 = LocalDate.of(1992, 10, 14);
       LocalDate date11 = LocalDate.of(1995, 9, 8);
       LocalDate date12 = LocalDate.of(1993, 3, 5);
       LocalDate date13 = LocalDate.of(2016, 1, 4);
       LocalDate date14 = LocalDate.of(2016, 1, 18);
       LocalDate date15 = LocalDate.of(2016, 9, 27);
       LocalDate date16 = LocalDate.of(2016, 12, 4);
       LocalDate date17 = LocalDate.of(2016, 11, 1);
       LocalDate date18 = LocalDate.of(2016, 8, 5);
      
       Person[] brides = new Person [6]; // Array to store bride names
       Person[] grooms = new Person [6]; // Array to store groom names

       brides[0] = new Person("Kimberly", "Hanson", date1); // Create New person
       grooms[0] = new Person("Mark", "Ziller", date2); // Create New person
      
       brides[1] = new Person("Janna", "Howard", date3); // Create New person
       grooms[1] = new Person("Julius", "Nemo", date4); // Create New person

       brides[2] = new Person("Tom", "Bilik", date5); // Create New person
       grooms[2] = new Person("Christina", "Donatella", date6); // Create New person

       brides[3] = new Person("Romeo", "Jonas", date7); // Create New person
       grooms[3] = new Person("Lisa", "Trier", date8); // Create New person

       brides[4] = new Person("Ricky", "Pitt", date9); // Create New person
       grooms[4] = new Person("Rose", "Adams", date10); // Create New person

       brides[5] = new Person("Rhaegar", "Targaryen", date11); // Create New person
       grooms[5] = new Person("Lyanna", "Stark", date12); // Create New person
      
       int i; // Iterator variable

       Couple[] couples = new Couple [6]; // Array to store couples
      
       // Iterate over the couple Array and set the couple details
       for (i = 0; i < 6; i++){
           couples[i] = new Couple(brides[i], grooms[i]); // Create New couple
       }
      
       Wedding[] weddings = new Wedding [6]; // Array to store weddings

       weddings[0] = new Wedding(couples[0], date13, "Mayfair Country Club"); // create a wedding and send it couple1, date5 and a place
       weddings[1] = new Wedding(couples[1], date14, "Oceanview Park"); // create a wedding and send it couple1, date5 and a place
       weddings[2] = new Wedding(couples[2], date15, "Sandhurst Road"); // create a wedding and send it couple1, date5 and a place
       weddings[3] = new Wedding(couples[3], date16, "Trevor's Eve"); // create a wedding and send it couple1, date5 and a place
       weddings[4] = new Wedding(couples[4], date17, "Radisson Park"); // create a wedding and send it couple1, date5 and a place
       weddings[5] = new Wedding(couples[5], date18, "Trent Bridge Social"); // create a wedding and send it couple1, date5 and a place
      
       // Iterate over the weddings Array and print the details
       for (i = 0; i < 6; i++){
           displayWeddingDetails(weddings[i]);
       }

   }

   // Displaying details of a wedding
   public static void displayWeddingDetails(Wedding w){
       // Getting the couple, person, location, and dates
       Couple couple = w.getCouple();
       LocalDate weddingDate = w.getWeddingDate();
       String location = w.getLocation();
       Person bride = couple.getBride();
       Person groom = couple.getGroom();
       String firstBride = bride.getFirstName();
       String lastBride = bride.getLastName();
       LocalDate brideBDate = bride.getBirthDate();
       String firstGroom = groom.getFirstName();
       String lastGroom = groom.getLastName();
       LocalDate groomBDate = groom.getBirthDate();

       //Printing the details
       System.out.println(" " + lastBride + "/" + lastGroom + " Wedding");
       System.out.println("Date: " + weddingDate + " Location: " +location);
       System.out.println("Bride: " + firstBride +" " + lastBride + " " + brideBDate);
       System.out.println("Groom: " + firstGroom +" " + lastGroom + " " + groomBDate);
   }
}

import java.time.*;
public class Person{

   // Person details
   private String firstName;
   private String lastName;
   private LocalDate birthDate;
  
   // Constructor
   public Person(String first, String last, LocalDate date){
       firstName = first;
       lastName = last;
       birthDate = date;
   }

   // Accessor functions
   public String getFirstName(){
       return firstName;
   }
   public String getLastName(){
       return lastName;
   }
   public LocalDate getBirthDate(){
       return birthDate;
   }
}

import java.time.*;
public class Couple{

   // Couple details
   private Person bride;
   private Person groom;
  
   public Couple(Person br, Person gr) { // couple constructor
       bride = br;
       groom = gr;
   }
  
   // Accessor functions
   public Person getBride(){
       return bride;
   }
   public Person getGroom(){
       return groom;
   }
}

import java.time.*;
public class Wedding {

   // Wedding details
   private Couple couple;
   private LocalDate weddingDate;
   private String location;
  
   public Wedding(Couple c, LocalDate date, String loc) { // wedding constructor
       couple = c;
       weddingDate = date;
       location = loc;
   }
  
   // Accessor functions
   public Couple getCouple(){
       return couple;
   }
   public LocalDate getWeddingDate(){
       return weddingDate;
   }
   public String getLocation(){
       return location;
   }
}

Sample output:

Hanson/Ziller Wedding
Date: 2016-01-04 Location: Mayfair Country Club
Bride: Kimberly Hanson 1986-12-14
Groom: Mark Ziller 1984-03-08

Howard/Nemo Wedding
Date: 2016-01-18 Location: Oceanview Park
Bride: Janna Howard 1991-04-17
Groom: Julius Nemo 1992-02-14

Bilik/Donatella Wedding
Date: 2016-09-27 Location: Sandhurst Road
Bride: Tom Bilik 1988-06-18
Groom: Christina Donatella 1988-06-25

Jonas/Trier Wedding
Date: 2016-12-04 Location: Trevor's Eve
Bride: Romeo Jonas 1990-04-20
Groom: Lisa Trier 1992-09-21

Pitt/Adams Wedding
Date: 2016-11-01 Location: Radisson Park
Bride: Ricky Pitt 1991-11-06
Groom: Rose Adams 1992-10-14

Targaryen/Stark Wedding
Date: 2016-08-05 Location: Trent Bridge Social
Bride: Rhaegar Targaryen 1995-09-08
Groom: Lyanna Stark 1993-03-05