Design and implement a simple inventory control system for a small video rental store.
import java.util.Scanner;
class Video {
String title;
boolean flag;
int avg_usr_rating;
Video() {
}
Video(String str) {
this.title = str;
}
boolean checked(String ti) {
this.flag = false;
return flag;
}
boolean returned(String ti) {
this.flag = true;
return flag;
}
int receivedrating(int a) {
this.avg_usr_rating = a;
return avg_usr_rating;
}
}
class VideoStore extends Video {
Video store[] = new Video[10];
int i = 0;
int rate[] = new int[10];
Video obj = new Video();
void addVideo(String str) {
System.out.println(str);
store[i] = new Video(str);
System.out.println(store[i].title);
i++;
System.out.println("---Video is Added---");
}
void checkOut(String str) {
boolean fl = false;
for (int j = 0; i < 10; j++) {
if (store[j].title.equals(str)) {
boolean f = obj.checked(str);
if (!f) {
System.out.println("Video is rented");
store[j] = new Video("nill");
}
fl = true;
break;
}
}
if (!fl) {
System.out.println("Video is not in the inventory");
}
}
void returnVideo(String str) {
boolean fl = false;
for (int j = 0; j < 10; j++) {
if (store[j].title.equals("nill")) {
boolean f = obj.returned(str);
if (f) {
store[j] = new Video(str);
System.out.println(" Video returned ");
}
fl = true;
break;
}
}
if (!fl) {
System.out.println("not returned yet");
}
}
void receiveRating(String str, int a) {
Object ob = str;
for (int j = 0; j < 10; j++) {
if (store[j].title.equals(ob)) {
rate[j] = a;
System.out.println("received the rating");
break;
}
}
}
void listinventory() {
for (int i = 0; i < this.i; i++) {
if(store[i].title != "nill"){
System.out.println("Video title: " + store[i].title + " ------rating : " + rate[i]);
System.out.println();
}
}
}
}
public class Film{
public static void main(String args[]) {
VideoStore temp = new VideoStore();
while (true) {
System.out.println("\n\n 1 - Add Video \n 2 - Checkout \n 3 - Return \n 4 - Rating \n 5 - Inventory \n 6 - Exit \n");
System.out.println(" Enter your Choice ");
System.out.print("Choose : ");
Scanner input = new Scanner(System.in);
int a = input.nextInt();
input.nextLine();
switch (a) {
case 1:
System.out.print("Enter the video title: ");
String str = input.nextLine();
temp.addVideo(str);
break;
case 2:
System.out.println("Enter the Video you are looking for: ");
String str1 = input.nextLine();
temp.checkOut(str1);
break;
case 3:
System.out.println("title of Video returning : ");
String str2 = input.nextLine();
temp.returnVideo(str2);
break;
case 4:
System.out.print("Enter the video name : ");
String str3 = input.nextLine();
System.out.print("Enter the rating: ");
int b = input.nextInt();
temp.receiveRating(str3, b);
break;
case 5:
System.out.println(" -- Inventory --");
temp.listinventory();
break;
default:
System.exit(0);
input.close();
}
}
}
}
0 Comments