java - How to add user input into an array -


this parent class

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()); }    } 

this child class:

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()); }  } 

this menu:

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 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 following options");         break;     } }  public static void addbook(){       }    } 

all want when user wants add book, user type in title , id , save array, , when done, go menu. cant seem knowledge @ moment.

i tried in addbook() method

holding[hold] = new book(); holding[hold].setbook(); 

the setbook method in book class, complete setbook, have make set methods method. when this, constructor undefined.

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());  } 

if there wrong code, please feel free me :d

thanks.

edit: after user adds book or video, when user wants print holdings, show title, id, loan fee , max loan period. how do that?

edit2: clean few parts wasn't necessary question

i suggest use "list of object" concept in handling it.

1) can define list of book object example.

list<book> booklist = new arraylist<book>(); 

2) everytime when hit addbook() function, can this.

//create temporary object of book user input data. book tempbook = new book(holdingidparam, titleparam);  //add them list booklist.add(tempbook); 

3) can use list likings, whether store them .txt based database or use them throughout program. usage example:

booklist.get(thedesiredindex).getbook() ... 

i not entirely sure of want after paying focus on bold text,this can understand case. feel free correct me on requirements if doesn't meet. hope helps :)


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -