Please help with this code? Movie - name string + rentMovie0) Write a class that
ID: 3751211 • Letter: P
Question
Please help with this code? Movie - name string + rentMovie0) Write a class that satisfies the following UML diagram and has aavailable : boolean constructor that always assigns available to true and allowsyear: int setting of the name and year attribute via the parameter, usereturnMovie() default values for params (your+ isAvailable(): boolean choice). Renting the media makes it unavailable (if it is currently unavailable, display a message that it cannot be rented) and returning it makes it available again. +str() string str (0 method should return a string such as "Movie Title (1900)Explanation / Answer
//Java program
import java.util.Scanner;
class Movie{
private boolean available;
private String name;
private int year;
public Movie() {}
public Movie(String name , int y) {
available = true;
this.name =name;
year = y;
}
public void rentMovie() {
available = false;
}
public void returnMovie()
{ available =true;
}
public boolean isAvailable() {
return available;
}
public String __str__() {
String str="";
return str+=name+" ("+year+")";
}
}
public class Movie_list {
public static void main(String args[]) {
Movie MovieList [] = new Movie[4];
MovieList[0]=new Movie("Lion King" ,1994);
MovieList[1]=new Movie("Dumb and Dumber" ,1994);
MovieList[2]=new Movie("Ghostbuster" ,1984);
MovieList[3]=new Movie("Grimlins" ,1984);
int rent=0;
int choice;
int count;
int temp;
Scanner in =new Scanner(System.in);
do {
System.out.println("1: Rent a movie ("+(4-rent)+" in stock)");
System.out.println("2: Return all movies ("+rent+" rented) 3:Quit");
System.out.print("What do you want to do ? : ");
choice = in.nextInt();
switch(choice) {
case 1:{temp=0;
System.out.println("Renting:");
for(int i=0;i<4;i++) {
if(MovieList[i].isAvailable()==true) {temp++;
System.out.println(temp +") "+MovieList[i].__str__());
}
}
System.out.print("what do you want to Rent? ");
count = in.nextInt();
int j=0;
while(count>0) {
if(MovieList[j].isAvailable()==true)count--;
j++;
}
MovieList[j-1].rentMovie();
rent++;
break;
}
case 2:{
for(int i=0;i<4;i++) {
if(MovieList[i].isAvailable()==false)MovieList[i].returnMovie();
}
}
}
}while(choice != 3);
in.close();
}
}