Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package christmas;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- public class Bag {
- private List<Present> data;
- private String color;
- private int capacity;
- public Bag(String color, int capacity) {
- this.color = color;
- this.capacity = capacity;
- this.data = new ArrayList<>();
- }
- public String getColor(String color) {
- return this.color;
- }
- public int getCapacity() {
- return this.capacity;
- }
- public int count() {
- return this.data.size();
- }
- public void add(Present present) {
- if (data.size() < capacity) {
- this.data.add(present);
- }
- }
- public String remove(String name) {
- if (this.data.removeIf(present -> present.getName().equals(name))){
- return "true";
- }else{
- return "false";
- }
- }
- public Present heaviestPresent(){
- Present present=null;
- double maxWeight=-1;
- for (Present p : data) {
- if (p.getWeight()>maxWeight){
- maxWeight=p.getWeight();
- present=p;
- }
- }
- return present;
- }
- // public Present getPresent(String name) {
- // return (Present) this.getPresent(name);
- // }
- public String report(){
- return String.format("%s bag contains: ",this.getColor());
- for (Present present : this.data) {
- System.out.println(present);
- }
- }
- public List<Present> getData() {
- return data;
- }
- public String getColor() {
- return color;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement