Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Call Parametrized Method from LibraryCollection Class to Main Class

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 473
    Answer it

    Hi Everybody!! 

    I am working on library management system project. Below is my LibraryCollection class. I would like to call my checkOutMaterial() method in the main class. 

    I need help on how to call the method.  Any help would be appreciated. 

     

    public class LibraryCollection 
    {
    	private int collectionMaxSize; 
    	private Material[] libraryCollection; 
    	
    	public LibraryCollection(int theMaxSize)
    	{
    		collectionMaxSize = theMaxSize; 
    		libraryCollection = new Material[collectionMaxSize]; 
    	}
    	
    	
    	public LibraryCollection(int theCollectSize, Material[] theArray)
    	{
    		collectionMaxSize = theCollectSize; 
    		libraryCollection = theArray; 
    	}
    
        //Material ID & checkedOutPtron ID; 
        public boolean checkOutMaterial(String matrlID, String patronId)
        {
            Material thisMaterial = findMaterial(matrlID); 
            if(thisMaterial == null) 
            {
                System.out.println("The material doesn't exist" ); 
                return false; 
            }
            if(thisMaterial.checkedOut())
            {
                System.out.println("The material has been already checked out " ); 
                return false; 
            }
            thisMaterial.setCheckedOut(true);
            thisMaterial.setPatronCheckout(Integer.parseInt(patronId));//Convert string value into int
    
        return true; 
        }

    //Material Class

    public class Material 
    {
        private static int materialID = 0 ; 
        private int mtrId; 
        private String title; 
        private boolean checkedOut ;
        private int checkedOutPatron; 
    
    
        public Material()
        {
            mtrId = 0; 
            title = ""; 
            checkedOut = false; 
            checkedOutPatron = 0; 
            }
    
        public Material(int theId, String theTitle)
        {
            mtrId = theId; 
            title = theTitle; 
        }
    
        //Getter Method 
        public String getMaterialId()
        {
            return mtrId + "";  
        }
    
        public String getTitle()
        {
            return title; 
        }
    
        public void setCheckedOut(boolean theCheckout)
        {
            checkedOut = theCheckout; 
        }
    
        public void setPatronCheckout(int patronCheckout)
        {
            checkedOutPatron = patronCheckout; 
        }
    
    
        public boolean checkedOut()
        {
            return checkedOut;
        }
        public int getCheckedOutPatron()
        {
            return checkedOutPatron; 
        }
    
    
        //ToString Method  
        public String toString()
            {
            return " \nMaterial ID: " + mtrId + " \nMaterial Title: " + title + " \nChecked Out: " 
            + checkedOut + " \nPatron check out: " + checkedOutPatron; 
            }
    
        public static int getNextID()
            {
            materialID++; 
            return materialID;
            }
    }

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: