Yeah, i stuck at Option 3, 4 and 5. Option 3, I've already done a bit but i don't know correct or not.
Option 3 doesn't do anything so i doubt it's correctGeSHi (java):
private static ArrayList<Hires> HireList = new ArrayList<Hires> ();
static void LoadHire(){
}
Created by GeSHI 1.0.7.20
What you can do is to take the code i wrote in case 5 and change it so that it adds each video that is hired in the HireList Array. Upon entering option 3, use a loop (like you did now) to show the HireList Array.Option 4, I have no idea how to count for No Of Hires( total number of days that each video has been hired is to displayed).
use the +getDateHired method in Hire and count the difference between the hired date and the current dateYour teacher already hinted you with the method to use:
GeSHi (java):
Hint: The
SimpleDateFormat in the java.
text package can be used to format the date.
df.format(currentDate);
Created by GeSHI 1.0.7.20
thank you very much.
I've also changed some of the code in your main so you can now add new video's and return to the selection screen:
GeSHi (java):
package videoHiringApplication;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static boolean stop = false;
public static void main
(String[]args
){
LoadCustomer();
LoadVideo();
LoadHire();
while(!stop){
LoadMainMenu();
Scanner in =
new Scanner
(System.
in);
int userinput = in.nextInt();
switch(userinput){
case 1:{
System.
out.
println("Customer ID\tCustomer Name\tPhone");
for(Customer x: Customers) {
System.
out.
print (x.
getcustomerid() +
"\t\t");
System.
out.
print (x.
getcustomername()+
"\t");
System.
out.
println (x.
getphone());
}
break;
}
case 2: {
System.
out.
println("ID\tName\t\t\tOnHire");
for(Video x: Videos) {
System.
out.
print (x.
getTitle());
System.
out.
println (x.
getOnHire());
}
break;
}
case 3: {
System.
out.
println("Hire ID\tVideo Name\tCustomer\tDate Hired");
System.
out.
println("=========================================");
for(Hires x: HireList) {
System.
out.
print (x.
getHireID());
System.
out.
print (x.
getHiredVideoName());
System.
out.
print (x.
getCustomer());
System.
out.
println (x.
getDateHired());
}
break;
}
case 4: {
System.
out.
println("Video ID\tVideo Name\tNo Of Hires");
System.
out.
println("==================================");
for(Video x: Videos) {
System.
out.
print (x.
getID() +
"\t\t");
System.
out.
print (x.
getTitle() +
"\t");
//System.out.println (x.NoOfHires());
}
break;
}
case 5:{
int j = 0;
boolean hireVideo = true;
Scanner in2 =
new Scanner
(System.
in);
while(hireVideo){
System.
out.
print("Customer Id: ");
custId = in2.nextLine();
for(int i = 0; i < Videos.length; i++){
if(Customers[i].getcustomerid().equals(custId)){
System.
out.
println(Customers
[i
].
getcustomerid() + Customers
[i
].
getcustomername());
System.
out.
println("already exist");
}
else{
System.
out.
print("Video Id ");
videoId = in2.nextLine();
if(Videos[i].getOnHire().equals("Yes")){
System.
out.
println("Video already hired");
}
else{
for(j = 0; j < Videos.length; j++){
j++;
}
Videos[j+1] = new Video(custId, videoId,"NO");
System.
out.
println("Video Hired");
break;
}
}
}
System.
out.
print("Enter another hire [Y/N]?");
hireVideoContinue = in2.nextLine();
if(hireVideoContinue.equals("N") || hireVideoContinue.equals("n")){
break;
}
}
}
case 6:{
}
case 7: {
//System.exit(0);
}
}
}
}
public static void LoadMainMenu(){
System.
out.
println ("MicroVideo Menu");
System.
out.
println ("================");
System.
out.
println ("1) List Customers" );
System.
out.
println ("2) List Videos");
System.
out.
println ("3) List Hires");
System.
out.
println ("4) Hire Statistics");
System.
out.
println ("5) Hire Video");
System.
out.
println ("6) Return Video");
System.
out.
println ("7) Quit");
System.
out.
print ("Enter selection: ");
}
private static Customer[] Customers = new Customer[3];
static void LoadCustomer(){
Customers[0] = new Customer ("C1000" , "Jim Barry", "43484001");
Customers[1] = new Customer ("C1001" , "Jim Barry", "43484001");
Customers[2] = new Customer ("C1002" ,"GeoffreyTan", "43480009");
}
private static Video[] Videos = new Video [8];
static void LoadVideo(){
Videos[0] = new Video ("100", "The Matrix 2","NO");
Videos[1] = new Video ("101", "Spiderman 3","NO");
Videos[2] = new Video ("102", "Shrek 2","NO");
Videos[3] = new Video ("103", "The Beach","NO");
Videos[4] = new Video ("104", "Sound of Music","NO");
Videos[5] = new Video ("105", "Planet of the Apes","NO");
Videos[6] = new Video ("106", "Moulin Rouge","NO");
Videos[7] = new Video ("107", "Lord of the Ring 1","NO");
}
private static ArrayList<Hires> HireList = new ArrayList<Hires> ();
static void LoadHire(){
}
}
Created by GeSHI 1.0.7.20
I could code this entire application myself but i'm quite busy atm so i can only give you hints instead of the entire sourcecode.