JAVA 1.2 HR
JAVA 1.2 HR
• Add Video: Add a video to the store by finding the first empty slot in the array
and creating a new Video object.
• Receive Rating: Update a video's average user rating based on new ratings received.
• Main Method:
• Create a VideoStore object.
• Add videos, receive ratings, check out and return videos as needed.
• List the inventory to show the current status.
• Code:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Video {
private String title;
private boolean available;
class Customer {
private String name;
class InventorySystem {
private List<Video> videos;
public InventorySystem() {
this.videos = new ArrayList<>();
}
while (true) {
System.out.println("\n1. Add Video\n2. Rent Video\n3. Display Inventory\n4. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Enter video title: ");
String title = scanner.next();
inventorySystem.addVideo(title);
break;
case 2:
System.out.print("Enter video title to rent: ");
title = scanner.next();
System.out.print("Enter customer name: ");
String customerName = scanner.next();
Customer customer = new Customer(customerName);
inventorySystem.rentVideo(title, customer);
break;
case 3:
inventorySystem.displayInventory();
break;
case 4:
System.out.println("Exiting the program.");
System.exit(0);
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}
• Result/Output: