Hi,
I need help coding the following subject.
this is the Subject
****************************************************
The program allows customers to list the videos available and to borrow them (ignore returning videos). It
records whether a video is on the shelf or on loan, and if it is on loan, the date it is due to be returned.
Customers can borrow up to two videos for 3 days. Build the program according to the following recipe:
1. There should be classes describing customers and videos and also a class called VideoStore that
contains ArrayLists of customers and videos. There should also be a small public class VideoTest
that contains the main() method.
2. The Video class has instance fields for the video title, whether it is on loan and the date it is due to be
returned. There are get and set methods for some of these fields and a toString() method.
3. The Customer class has instance fields for the customer name and for the number of videos he is
borrowing. A method borrowvideo(Video v) checks that the video is available and that the
customer is not borrowing more than 2 videos, it then sets the duedate and onloan fields in the Video
class. The due date is printed on screen. There is a get method for the customer name.
4. The constructor for the VideoStore class initialises a small number (less than 10) of Customer and
Video objects and stores them in two separate ArrayLists that are the instance fields for the class. It
provides a method (listallvideos()) for listing all the videos in the store and a method called
borrow(String,String) described below.
5. The main method in VideoTest creates a VideoStore, then enters a loop that implements a menu:
"Menu: L-List, B-Borrow, Q-Quit". A Scanner picks up the letter entered and causes the desired
response. List, lists the titles of all the videos along with whether they are on the shelf or the due date
if they are on loan. Quit, drops out of the loop and exits the application. Borrow, asks first the
Customer's name, and then the title of the video he wishes to borrow and picks up responses with a
Scanner. These are then passed to the VideoStore borrow method as borrow(name,title).
6. The VideoStore borrow method checks that the name and title match entries in the VideoStore arrays,
and identifies the Customer and Video objects they correspond to. The Customer
borrowvideo(Video v) method can then be called.
*************************************
VideoTest Class
*************************************
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package assignement;
import java.util.*;
/**
*
* @author Harris
*/
public class VideotTest {
public static void main(String[] args)
{
//VideoStore vs = new VideoStore();
VideoStore vs = new VideoStore();
Scanner sc = new Scanner(System.in);
String menuResponse;
do
{
System.out.println("Menu: L-list, B-borrow, Q-quit");
menuResponse = sc.nextLine();
if(menuResponse.equals("L"))
vs.listallvideos();
else if (menuResponse.equals("B"))
{
System.out.println("What is your name?");
String nameResponse = sc.nextLine();
System.out.println("What is the title of the video you want to borrow?");
String videoResponse = sc.nextLine();
//vs.borrow(nameResponse,videoResponse);
}
} while(!menuResponse.equalsIgnoreCase("Q"));
}
}
**********************************
Customers Class
**********************************
public class Customers {
private String cutNames;
private int Nbrvideo;
public Customers(String cn){
cutNames = cn;
//NbrVideo = nv;
}
public String getCuName(){
return cutNames;
}
public int getNbrVideo(){
return Nbrvideo;
}
***********************************
Video Class
***********************************
public class Video {
private String videotitle;
private String status;
private Date due;
public Video(String vidTitle, String s){
videotitle = vidTitle;
}
public String getVideoTitle(){
return videotitle;
}
public void setVideoTitle(String vidtitle){
videotitle = vidtitle;
}
public String getStatus(){
return status;
}
public void setStatus(String stat){
status = stat;
}
public Date getDate(){
return due;
}
public void setDate(Date du){
due = du;
}
}
*******************************************
VideoStore Class
*******************************************
public class VideoStore {
private ArrayList<Video> Videos = new ArrayList<Video>();
private ArrayList<Customers> CustomersListe = new ArrayList<Customers>();
public VideoStore(){
Videos.add(new Video("Brave Heart",""));
Videos.add(new Video("Troy",""));
Videos.add(new Video("Shakspear In Love",""));
Videos.add(new Video("Green Mile",""));
Videos.add(new Video("Ice Age",""));
CustomersListe.add(new Customers("Harris"));
CustomersListe.add(new Customers("John"));
CustomersListe.add(new Customers("Ricky"));
CustomersListe.add(new Customers("Mike"));
CustomersListe.add(new Customers("Robin"));
}
public void listallvideos(){
for (int i = 0; i < Videos.size(); i++)
System.out.println(Videos.get(i).getVideoTitle());
}
public void borrow(String cn, String vn){
for (int i = 0; i < Videos.size(); i++){
for (int x = 0; x < CustomersListe.size(); x++)
if(CustomersListe.get(x).getCuName().equals(cn))
if(Videos.get(i).getVideoTitle().equals(vn))
if(CustomersListe.get(x).getNbrVideo()<2)
Videos.get(i).setVideoTitle(vn);
{
}
}
}
}
I am stuck in doing the public void borrow methode anyone can help please?
thanks