Answer to Question #237044 in Java | JSP | JSF for gee

Question #237044

Define a class named Person that contains the data fields for the first name and last name. Include only a non-default constructor that that initializes the data fields and a method that displays all the information about a Person. b) Define another class named Movie that stores a title, year of production and a director information. Director should be a Person member-object (i.e. use the Person class). Include a non-default constructor and a function to display Movie information. c) Write a program that creates two Movie objects, and displays information about the Movie objects. Save the file as Cinema.jav


1
Expert's answer
2021-09-14T18:05:07-0400



class Person {
	private String firstName;
	private String lastName;


	public Person() {
		this.firstName = "";
		this.lastName = "";
	}


	public Person(String firstName, String lastName) {
		this.firstName = firstName;
		this.lastName = lastName;
	}


	public void display() {
		System.out.println("First name: " + firstName);
		System.out.println("Last name: " + lastName);
	}


	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}


	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}


	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}


	/**
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
}


class Movie {
	private String title;
	private int yearProduction;
	private Person director;


	public Movie() {
		this.title = "";
		this.yearProduction = 2020;
		this.director = new Person("", "");
	}


	public Movie(String title, int yearProduction, Person director) {
		this.title = title;
		this.yearProduction = yearProduction;
		this.director = director;
	}


	public void display() {
		System.out.println("Title: " + title);
		System.out.println("Year production: " + yearProduction);
		this.director.display();
	}


	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}


	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}


	/**
	 * @return the yearProduction
	 */
	public int getYearProduction() {
		return yearProduction;
	}


	/**
	 * @param yearProduction the yearProduction to set
	 */
	public void setYearProduction(int yearProduction) {
		this.yearProduction = yearProduction;
	}


	/**
	 * @return the director
	 */
	public Person getDirector() {
		return director;
	}


	/**
	 * @param director the director to set
	 */
	public void setDirector(Person director) {
		this.director = director;
	}
}


public class Main {
	public static void main(String[] args) {
		// creates two Movie objects, and displays information about the Movie objects.
		Movie movie1 = new Movie("Title 1", 2020, new Person("Mary", "Clark"));
		Movie movie2 = new Movie("Title 2", 2018, new Person("Peter", "Smith"));
		movie1.display();
		movie2.display();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS