Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Item heaviestItem(){
- //If no items are in the ArrayList<Item>, then return null.
- if(this.items.isEmpty()){
- return null;
- }
- //Create new object with first item in Arraylist<Item>
- Item heaviestItem = this.items.get(0);
- //Go through all the items in the Arraylist<Item> and find the heaviest one.
- for (Item item:this.items){
- if(heaviestItem.getWeight()<item.getWeight()){
- heaviestItem = item;
- }
- }
- return heaviestItem;
- }
Advertisement
Add Comment
Please, Sign In to add comment