2016-05-28 153 views
-1

我不知道如何去做必须创建的库菜单中的borrowHolding()。 所以,borrowHolding()的目的是让成员能够借阅书籍或视频。图书馆系统:借用

这是一个只是阵列的示例数据:

member[0] = new StandardMember("ID", "Name"); 
member[1] = new PremiumMember("ID", "Name"); 
holding[0] = new Book("ID", "Title"); 
holding[1] = new Video("ID", "Title", loanFee); 

这是TestLibrary类的borrowHolding()方法:(数组是在TestLibrary类太)

public static void borrowHolding(){ 
    String option; 
    option = input.next(); 

do{ 

    Scanner scan = new Scanner(System.in); 
    int tempId = 0; 
    System.out.println("Enter your ID: "); 
    String searchID = scan.next(); 

    for(int i = 0; i < member.length; i++){ 

     if(member[i].getID().equals(searchID)){ 

       tempId = i; 

      } 
     } 

因此,对于该方法,我试图编写一个代码,它将搜索数组以查找想要借用的memberID。这是因为我相信我没有这样做正确

有包含

public class Member{ 

    public Holding[] getCurrentHoldings(){ 
    } 

} 
从方法的名称

会员类,它是用来存储成员的减持还没有完成的借来的。所以如果成员1借了一本书,我想这本书会存储在数组中。我正在考虑为这种方法使用ArrayList,但不确定它是否合理。

借用一本书或一个视频,有一定条件可以借用,但我不知道如何将其实现到borrowHolding()中。其中一个条件是在Holding类中。

public class Holding{ 
    public boolean borrowHolding(){ 
     if(status == true && isOnLoan() == false) 
      borrowDate = newDateTime(); //this is to get the time when the book or video is borrowed 

      return true; 
     }else 
      return false; 

    } 
} 

而且会员类还有另一个条件是会员必须有足够的借贷借贷。图书贷款费用为10美元,视频将从4美元或6美元不等。

我想我写了一些不需要的信息,但我想它比信息少。

我的问题是我该怎么做LibraryMenu中的borrowHolding()方法?我怎么做,如果一个成员想借保持,保持会成员的数组下走在成员类

public class Member{ 

    public Holding[] getCurrentHoldings(){ 
    } 

} 

从担任班级的条件如果满足,但在执行借用管理方法,从成员类中的方法将能够从书或视频中减去贷款费用的成员信用。可能吗?

public class Member{ 
    private int credit = 30; 
    public int calculateRemainingCredit(){ 

     credit = credit - //(the loan fee from the book or video class) 

    } 
} 

回答

0

如果你的意图是要添加一个持有成员类,那么这是可能的。我会建议添加Holding's ArrayList而不是常规数组,因为它看起来好像大小会不断变化。

public class Member{ 
    private ArrayList<Holding> currentholdings; // you may need to import the arraylist 
    private int credit; 

    public void init(){ // goes in constructor 
     currentholdings = new ArrayList<Holding>(); 
     credit=0; 
    } 

    public void addHolding(Holding newholding){ // adds a new holding to the members array 
     currentholdings.add(newholding); 
     credit-=newholding.getFee(); // will need to add a fee variable to the holding class; 
    } 
} 

至于检查,以查看该成员是否有足够的“信用”,能在之后您识别数组的索引borrowHolding()方法来实现。我只是建议将该成员的参数添加到borrowHolding()方法中,以便您可以轻松地访问该成员的变量。

if(member[i].getID().equals(searchID)){ 
    tempId = i; 
    int tempHolding; // index of whatever holding you wanted (could get this from the scanner) 

    if (holding[tempHolding].borrowHolding(member[tempId])){ // check status 
     member[tempId].addHolding(holding[tempHolding]); // they have passed the req. so you can add the holding 
    } 

    break; 
} 

希望这回答了你的问题。