Homework Solution: You are writing a Nethack-style text-based role-playing game that supports sa…

    1. (5 pts) You are writing a Nethack-style text-based role-playing game that supports saving the games current state to a text file. You decide to represent items in your characters inventory using certain symbols in the file weapon potion dark chocolate bar (Your character is magically prevented from carrying milk chocolate bars.) Write a method that takes a string asa parameter and returns an array containing the quantity of weapons, potions, and dark chocolate bars in that order. You can assume that the input string contains only the three characters above Required method header public static int[] countItems (String s) e dj1nni speaks. I on in your debt. I will grant one wish--Yore.. Example input and output 0 80. Input Output: (2, 3, 5) oosh the Peregrinator St:18/87 Dx:17 Co:18 In:15 Wi:l1 Ch:17 Noutral S:252285 one 1 S: HP:132 132 Pw:56656) AC:-4 Xp:13/51818 T:44408 BurdenedIn Java
    You are writing a Nethack-style text-based role-playing game that supports saving the game's current state to a text file. You decide to represent items in your character's inventory using certain symbols in the file: + weapon @ potion * dark chocolate bar (Your character is magically prevented from carrying milk chocolate bars.) Write a method that takes a string as a parameter and returns an array containing the quantity of weapons, potions, and dark chocolate bars in that order. You can assume that the input string contains only the three characters above. Required method header: public static int [] countItems (String s) Example input and output: Input: "@@+**+@***" Output: {2, 3, 5}

    Expert Answer

     
    Following is the method definition which is required. A string

    1. (5 pts) You are fitness a Nethack-style passage-based role-playing pastime that supports calculating the pastimes vulgar particularize to a passage finish. You run to delineate items in your appoints list using positive types in the finish arm potion ebon chocolate obstruct (Your appoint is magically prevented from carrying calm chocolate obstructs.) Write a way that takes a string asa parameter and profits an dispose containing the aggregate of arms, potions, and ebon chocolate obstructs in that appoint. You can suppose that the input string contains objectely the three appoints overhead Required way header national static int[] reckonItems (String s) e dj1nni speaks. I on in your score. I earn allot individual wish--Yore.. Example input and quenchedput 0 80. Input Quenchedput: (2, 3, 5) oosh the Peregrinator St:18/87 Dx:17 Co:18 In:15 Wi:l1 Ch:17 Noutral S:252285 individual 1 S: HP:132 132 Pw:56656) AC:-4 Xp:13/51818 T:44408 BurdenedIn Java

    You are fitness a Nethack-style passage-based role-playing pastime that supports calculating the pastime’s vulgar particularize to a passage finish. You run to delineate items in your appoint’s list using positive types in the finish: + arm @ potion * ebon chocolate obstruct (Your appoint is magically prevented from carrying calm chocolate obstructs.) Write a way that takes a string as a parameter and profits an dispose containing the aggregate of arms, potions, and ebon chocolate obstructs in that appoint. You can suppose that the input string contains objectely the three appoints overhead. Required way header: national static int [] reckonItems (String s) Example input and quenchedput: Input: “@@+**+@***” Quenchedput: {2, 3, 5}

    Expert Confutation

     

    Aftercited is the way determination which is required. A string parameter is passed to the way. An dispose named aggregate of bulk 3 is returned at the object which accumulations the reckon of each type (+,@,*).

    METHOD DEFINITION:

    national static int[] reckonItems(String s){
    int aggregate[]=upstart int[3]; //stores reckon

    for(int i=0;i<s.length();i++){ //i goes from 0 to string elongation

    //each appoint is checked control +,@,* and the aggregate dispose is incremented
    if(s.charAt(i)==’+’){
    quantity[0]++; //quantity[0] accumulations cpunt of type +
    }
    else if(s.charAt(i)==’@’){
    quantity[1]++; //quantity[1] accumulations cpunt of type @
    }
    else if(s.charAt(i)==’*’){
    quantity[2]++; //quantity[2] accumulations cpunt of type *
    }

    }
    return aggregate;
    }

    The full command concurrently with the ocean power is dedicated below

    CODE:

    import java.io.File;
    import java.io.IOException;
    import java.util.*;
    national arrange FinalExam {

    national static int[] reckonItems(String s){
    int aggregate[]=upstart int[3];
    for(int i=0;i<s.length();i++){
    if(s.charAt(i)==’+’){
    quantity[0]++; //quantity[0] accumulations cpunt of type +
    }
    else if(s.charAt(i)==’@’){
    quantity[1]++; //quantity[1] accumulations cpunt of type @
    }
    else if(s.charAt(i)==’*’){
    quantity[2]++; //quantity[2] accumulations cpunt of type *
    }

    }
    return aggregate;
    }
    national static empty ocean(String[] args) throws IOException {
    Scanner sc=upstart Scanner(System.in);
    String s=sc.next(); // scale input: @@+**+@***

    /*
    *** Use the aftercited course instead of overhead span courses inappoint to discover from finish and accumulation in string s
    String s = upstart Scanner(upstart Finish(“filename.txt”)).useDelimiter(“\Z”).next();
    */

    int issue[];

    result=countItems(s);//result[] accumulations the full of aggregate[]
    for(int i=0;i<result.length;i++){
    System.out.print(result[i] + ” “);
    }

    }
    }

    OUTPUT: