Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Spieler
  4. {
  5. private ArrayList<Gegenstand>items;
  6. private int aktGewicht;
  7. private int maxWeight;
  8.  
  9. public Spieler(){
  10.  
  11. items = new ArrayList<Gegenstand>();
  12. this.aktGewicht=0;
  13. this.maxWeight=1000;
  14. }
  15.  
  16. public void addItem(Gegenstand item){
  17. boolean istGenugGewicht=false;
  18. if(item.gibGewicht()+aktGewicht<maxWeight){
  19. istGenugGewicht=true;
  20. }
  21. if(istGenugGewicht){
  22. this.items.add(item);
  23. }
  24. }
  25.  
  26. public void removeItem(Gegenstand item){
  27. for(int i=0; i<items.size();i++){
  28. if(item.gibBeschreibung().equals(items.get(i).gibBeschreibung())){
  29. items.remove(i);
  30. }
  31. }
  32. }
  33.  
  34. public void gibAlleItems(){
  35. if(items.size()==0){
  36. System.out.println("Sie tragen im moment keine Gegenstaende bei sich.");
  37. }
  38. else{
  39. System.out.println("Sie tragen im moment: ");
  40. for(int i=0;i<items.size();i++){
  41. System.out.print(items.get(i));
  42. }
  43. }
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement