Это родительский классКак добавить пользовательский ввод в массив
public class Holding {
private String holdingId, title;
private int defaultLoanFee, maxLoanPeriod, calculateLateFee;
public Holding(String holdingId, String title){
this.holdingId = holdingId;
this.title = title;
}
public String getId(){
return this.holdingId;
}
public String getTitle(){
return this.title;
}
public int getDefaultLoanFee(){
return this.defaultLoanFee;
}
public int getMaxLoanPeriod(){
return this.maxLoanPeriod;
}
public void print(){
System.out.println("Title: " + getTitle());
System.out.println("ID: " + getId());
System.out.println("Loan Fee: " + getDefaultLoanFee());
System.out.println("Max Loan Period: " + getMaxLoanPeriod());
}
}
Это дочерний класс:
public class Book extends Holding{
private String holdingId, title;
private final int defaultLoanFee = 10;
private final int maxLoanPeriod = 28;
public Book(String holdingId, String title){
super(holdingId, title);
}
public String getHoldingId() {
return holdingId;
}
public String getTitle(){
return title;
}
public int getDefautLoanFee(){
return defaultLoanFee;
}
public int getMaxLoanPeriod(){
return maxLoanPeriod;
}
public void print(){
System.out.println("Title: " + getTitle());
System.out.println("ID: " + getHoldingId());
System.out.println("Loan Fee: " + getDefaultLoanFee());
System.out.println("Max Loan Period: " + getMaxLoanPeriod());
}
}
Это меню:
public class LibraryMenu {
static Holding[]holding = new Holding[15];
static int hold = 0;
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int options = keyboard.nextInt();
do{
}
System.out.println();
System.out.println("Library Management System");
System.out.println("1. Add Holding");
System.out.println("2. Remove Holding");
switch(options){
case 1:
addHolding();
break;
default:
System.out.println("Please enter the following options");
}
}while(options == 13);
System.out.println("Thank you");
}
public static void addHolding(){
System.out.println("1. Book");
System.out.println("2. Video");
int input1 = input.nextInt();
switch(input1){
case 1:
addBook();
break;
case 2:
addVideo();
break;
default:
System.out.println("Please select the following options");
break;
}
}
public static void addBook(){
}
}
Все я хочу, когда пользователь хочет добавить книгу, пользователь будет вводить в нее заголовок и идентификатор, и он будет сохраняться в массиве, а когда это делается, он вернется в меню. Кажется, я не знаю, как это сделать.
я попытался сделать это в методе addBook()
holding[hold] = new Book();
holding[hold].setBook();
метод SetBook бы в классе Book, чтобы завершить SetBook, я должен сделать набор методов для всех метода GET. Но когда я это делаю, конструктор не определен.
public void setBook(){
System.out.println("Title: " + setTitle());
System.out.println("ID: " + setHoldingId());
System.out.println("Loan fee: " + setDefaultLoanFee());
System.out.println("Max Loan Period: " + setMaxLoanPeriod());
}
Если есть что-то случилось с моим кодом, пожалуйста, не стесняйтесь сказать мне: D
Спасибо.
Редактировать: После того, как пользователь добавит книгу или видео, когда пользователь хочет распечатать все холдинги, он отобразит заголовок, идентификатор, сумму кредита и максимальный срок кредита. Как мне это сделать?
edit2: Очистка несколько частей, которые не нужно было с моим вопросом
Дайте нам минимальное количество кода, который имеет отношение к вопросу, а не вся вещь – Li357
это не вся вещь, думал, что это имеет отношение – HelpwAssignments
@HelpwAssignments [MCVE] (HTTP: // WWW .stackoverflow.com/help/mcve) –