Question
given the following code how would I return an item Return an item. The user inputs the id of the requested item. If the item
given the following code how would I return an item
"Return an item. The user inputs the id of the requested item. If the item is not overdue, the item is being returned, the system displays a successful message; otherwise, the system displays the amount of the late fee that is due."
package EFF;
import java.util.ArrayList;
import java.util.Scanner;
import java.time.LocalDate;
import java.time.Period;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.List;
/**
*
* @author Ferro
* @version 1
*/
public abstract class EF {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int choice = 0;
List
while (true) {
displayMenu();
while (true) {
try {
choice = input.nextInt();
break;
} catch (InputMismatchException e) {
input.nextLine();
System.out.print("You must enter an integer");
}
}
switch (choice) {
case 1:
System.out.println("Enter book title: ");
input.nextLine();
String name = input.nextLine();
System.out.println("Enter book author: ");
String author = input.nextLine();
System.out.println("Enter Number of Pages: ");
int npages = -1;
while (npages == -1) {
try {
npages = input.nextInt();
} catch (InputMismatchException e) {//invalid input not numeric
System.out.println("Invalid input must be numeric ");
npages = -1;
input.nextLine();
}
}
Book b = new Book(0, name);
b.setAuthor(author);
b.setNumPages(npages);
System.out.println("Added");
System.out.println(b);
list.add(b);
break;
case 2:
System.out.print("Enter CD title: ");
input.nextLine();
String title = input.nextLine();
System.out.print("Enter CD artist: ");
String artist = input.nextLine();
System.out.print("Enter Number of Tracks: ");
int ntracks = -1;
while (ntracks == -1) {
try {
ntracks = input.nextInt();
} catch (InputMismatchException e) {
System.out.println("Invalid input must be numeric ");
ntracks = -1;
input.nextLine();
}
}
CD c = new CD(0, title);
c.setArtist(artist);
c.setNumTracks(ntracks);
System.out.println("Added");
System.out.println(c);
list.add(c);
break;
case 3:
System.out.print("Enter DVD title: ");
input.nextLine();
String movie = input.nextLine();
System.out.print("Enter DVD director: ");
String director = input.nextLine();
System.out.print("Enter duration: ");
int ntime = -1;
while (ntime == -1){
try {
ntime = input.nextInt();
} catch (InputMismatchException e) {
System.out.println("Invalid input must be numeric ");
ntime = -1;
input.nextLine();
}
}
DVD d = new DVD(0, movie);
d.setDirector(director);
d.setDuration(ntime);
System.out.println("Added");
System.out.println(d);
list.add(d);
break;
case 4:
System.out.print("Enter id: ");
int id = -1;
while (id == -1) {
try {
id = input.nextInt();
} catch (InputMismatchException e) {
System.out.println("Invalid input must be numeric ");
npages = -1;
input.nextLine();
}
}
displayItem(list, id);
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
System.out.println("Existing the system");
System.exit(0);
break;
default:
System.out.println("Oops Wrong Input.");
break;
}
}
}
public static void displayItem(List
for (Iterator
Library next = iterator.next();
if(next.getId() == id) {
System.out.println(next);
break;
}
}
}
public static void displayMenu() {
System.out.println("Select one from the following options:");
System.out.println("1 - Add a new book ");
System.out.println("2 - Add a new CD ");
System.out.println("3 - Add a new DVD ");
System.out.println("4 - Display an item ");
System.out.println("5 - Check out an item ");
System.out.println("6 - Return an item ");
System.out.println("7 - Search for items with keyword ");
System.out.println("8 - Remove an item ");
System.out.println("9 - Quit the program ");
}
}// end of the class
//////////////////////////////////////////////////////////////////////////
package EFF;
import java.time.LocalDate;
import java.time.Period;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Ferro
*/
public abstract class Library {
private int id;
private String title;
private int dueDate;
LocalDate dateOfRent;
Period period;
private static int nextId = 1001;
public Library(int id, String title) {
this.id = id;
this.title = title;
dateOfRent = LocalDate.now();
this.period = period;
this.id = nextId;
nextId++;
}
public int getId() {
return id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public LocalDate getDateOfRent() {
return dateOfRent;
}
public void setDateOfRent(LocalDate dateOfRent) {
this.dateOfRent = dateOfRent;
}
public Period getPeriod() {
return period;
}
public void setPeriod(Period period) {
this.period = period;
}
@Override
public String toString() {
return "id: " + id + ", title: " + title;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started