Untitled

 avatar
unknown
java
2 years ago
1.7 kB
2
Indexable
import java.util.ArrayList;
import java.util.List;

class Documentary {
    private String title;
    private String description;
    private int yearProduced;
    private List<String> landmarks;

    public Documentary(String title, String description, int yearProduced) {
        this.title = title;
        this.description = description;
        this.yearProduced = yearProduced;
        this.landmarks = new ArrayList<>();
    }

    public void addLandmark(String landmark) {
        landmarks.add(landmark);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Title: ").append(title).append("\n");
        sb.append("Description: ").append(description).append("\n");
        sb.append("Year Produced: ").append(yearProduced).append("\n");
        sb.append("Landmarks in India:\n");
        for (String landmark : landmarks) {
            sb.append("- ").append(landmark).append("\n");
        }
        return sb.toString();
    }
}

public class IndiaDocumentary {
    public static void main(String[] args) {
        // Create a new Documentary about India
        Documentary indiaDocumentary = new Documentary("India: A Journey Through History",
                "Discover the rich history and cultural heritage of India.", 2023);

        // Add landmarks to the documentary
        indiaDocumentary.addLandmark("Taj Mahal");
        indiaDocumentary.addLandmark("Red Fort");
        indiaDocumentary.addLandmark("Qutub Minar");
        indiaDocumentary.addLandmark("Hampi");
        indiaDocumentary.addLandmark("Ajanta and Ellora Caves");

        // Print the information about the documentary
        System.out.println(indiaDocumentary);
    }
}
Editor is loading...