Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String toString() { // returns information about the object Item, getting data from this same Class Item
- return "Item:" +
- "%n * Strength: " + strength +
- "%n * Agility: " + agility +
- "%n * Intelligence: " + intelligence;
- __________________________________________________________________________________________________________________________________________
- @Override // returns information about the object Hero, getting data from both Class Hero and Class Item
- public String toString() {
- return "Hero: " + name + " - " + level + "\n" + item.toString(); }
- __________________________________________________________________________________________________________________________________________
- public class HeroRepository {
- private Map<String, Hero> data;
- public HeroRepository() {
- this.data = new HashMap<>(); }
- public void add(Hero hero) {
- this.data.put(hero.getName(), hero); }
- public void remove(String name) {
- this.data.remove(name); }
- public int getCount() {
- return this.data.size(); }
- public Hero getHeroWithHighestStrength() {
- return this.data.values()
- .stream()
- .sorted((f, s) -> s.getItem().getStrength() - f.getItem().getStrength())
- .collect(Collectors.toList())
- .get(0);
- }
- @Override
- public String toString() { // returns information about all Heroes in the Map
- return String.join("\n",
- this.data.values()
- .stream()
- .map(Hero::toString)
- .collect(Collectors.toList()));
- _______________________________________________________________________________________________________________________________________
- SECOND TASK:
- ________________________________________________________________________________________________________________________________________
- private List<Astronaut> data;
- public void add(Astronaut astronaut) { // add method with curtain condition
- if (data.size() < capacity) {
- data.add(astronaut);
- }
- _________________________________________________________________________________________________________________________________________
- public Astronaut getOldestAstronaut() { // gets the biggest value in a List of objects
- return data.stream().max((f, s) -> Integer.compare(f.getAge(), s.getAge())).get();
- }
- __________________________________________________________________________________________________________________________________________
- public Astronaut getAstronaut(String name) { // returns a certain object
- Astronaut givenName = null;
- for (Astronaut astronaut : this.data) {
- if (astronaut.getName().equals(name)) {
- givenName = astronaut;
- }
- }
- return givenName;
- }
- _________________________________________________________________________________________________________________________________________
- public String report() { // returns a String
- StringBuilder sb = new StringBuilder();
- sb.append("Astronauts working at Space Station ").append(name).append(":");
- for(Astronaut a: data){
- sb.append(System.lineSeparator()).append(a.toString());
- }
- return sb.toString().trim();
- _________________________________________________________________________________________________________________________________________
- THIRD TASK:
- _________________________________________________________________________________________________________________________________________
- public class Gladiator {
- private Stat stat;
- public int getStatPower(){ // returns info getting data from other Class - Stat.
- return this.stat.getAgility()+this.stat.getFlexibility()
- +this.stat.getIntelligence()+this.stat.getSkills()+this.stat.getStrength();
- }
- }
- ________________________________________________________________________________________________________________________________________
- public Gladiator getGladiatorWithHighestStatPower(){
- Gladiator toReturn = new Gladiator("",new Stat(0,0,0,0,0),new Weapon(0,0,0));
- for (Gladiator g: this.gladiators.values()){
- if(g.getStatPower()>toReturn.getStatPower()){
- toReturn = g;
- }
- }
- return toReturn;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement