Question

In: Computer Science

Problem with code. The fixed code would be greatly appreciated! Error messages: PlayerMoveDungeon2.java:21: error: cannot find...

Problem with code. The fixed code would be greatly appreciated!

Error messages:

PlayerMoveDungeon2.java:21: error: cannot find symbol
for (i = 0; i < length; i++) {
^
symbol: variable i
location: class PlayerMoveDungeon2
PlayerMoveDungeon2.java:21: error: cannot find symbol
for (i = 0; i < length; i++) {
^
symbol: variable i
location: class PlayerMoveDungeon2
PlayerMoveDungeon2.java:21: error: cannot find symbol
for (i = 0; i < length; i++) {
^
symbol: variable i
location: class PlayerMoveDungeon2
PlayerMoveDungeon2.java:22: error: cannot find symbol
char myChar = moveChar.charAt(i);
^
symbol: variable i
location: class PlayerMoveDungeon2
PlayerMoveDungeon2.java:32: error: cannot find symbol
for (i = 0; i < width; i++) {
^
symbol: variable i
location: class PlayerMoveDungeon2
PlayerMoveDungeon2.java:32: error: cannot find symbol
for (i = 0; i < width; i++) {
^
symbol: variable i
location: class PlayerMoveDungeon2
PlayerMoveDungeon2.java:32: error: cannot find symbol
for (i = 0; i < width; i++) {
^
symbol: variable i
location: class PlayerMoveDungeon2
PlayerMoveDungeon2.java:33: error: cannot find symbol
myChar = moveChar.chatAt(i);
^
symbol: variable i
location: class PlayerMoveDungeon2
PlayerMoveDungeon2.java:45: error: no suitable method found for println(int,int)
System.out.println(x, y);
^
method PrintStream.println() is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(boolean) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(char) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(int) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(long) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(float) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(double) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(char[]) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(String) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(Object) is not applicable
(actual and formal argument lists differ in length)
9 errors

Code:

import java.util.Scanner;

public class PlayerMoveDungeon2 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int cases = input.nextInt();

        int length = 0;

        int width = 0;

        int x = 0;

        int y = 0;

        for (int i = 0; i < cases; i++) {

            length = input.nextInt();

            width = input.nextInt();

        }

        {

            x = input.nextInt();

            y = input.nextInt();

        }

        String moveChar = input.nextLine();

        moveChar.replaceAll(" ", "");

        for (i = 0; i < length; i++) {

            char myChar = moveChar.charAt(i);

            if (myChar == 'W' || myChar == 'w') {

                if (y > 0) {

                    y--;

                }

            }

            if (myChar == 'S' || myChar == 's') {

                if (y < length)

                    y++;

            }

            for (i = 0; i < width; i++) {

                myChar = moveChar.chatAt(i);

                if (myChar == 'A' || myChar == 'a') {

                    if (x > 0) {

                        x--;

                    }

                }

                if (myChar == 'D' || myChar == 'd') {

                    if (x < width) {

                        x++;

                    }

                }

            }

            System.out.println(x, y);

        }

    }

}

Solutions

Expert Solution

Program:

import java.util.Scanner;

public class PlayerMoveDungeon2 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int cases = input.nextInt();

        int length = 0;

        int width = 0;

        int x = 0;

        int y = 0;
        
        int i; // Initializing variable i since you have been using it for other loops

        for (i = 0; i < cases; i++) {

            length = input.nextInt();

            width = input.nextInt();

        }

        {

            x = input.nextInt();

            y = input.nextInt();

        }

        String moveChar = input.nextLine();

        moveChar.replaceAll(" ", "");

        for (i = 0; i < length; i++) {

            char myChar = moveChar.charAt(i);

            if (myChar == 'W' || myChar == 'w') {

                if (y > 0) {

                    y--;

                }

            }

            if (myChar == 'S' || myChar == 's') {

                if (y < length)

                    y++;

            }

            for (i = 0; i < width; i++) {

                myChar = moveChar.charAt(i); // It's typo mistake charAt() is the function name

                if (myChar == 'A' || myChar == 'a') {

                    if (x > 0) {

                        x--;

                    }

                }

                if (myChar == 'D' || myChar == 'd') {

                    if (x < width) {

                        x++;

                    }

                }

            }

            System.out.println(x+ " "+y); // Use + to print multiple results

        }

    }

}

Note: Please find the comments in the code


Related Solutions

Any advice or recommendation would be greatly appreciated You are the sport agent for a rising...
Any advice or recommendation would be greatly appreciated You are the sport agent for a rising basketball star just drafted in the first round. Your client has two offers on the table option $90 million dollars over 5 years or option $30 million signing bonus and 40 million over the next 3 yrs. What option do you recommend? How does the time value of money impact your decision?
If you could show work it would be greatly appreciated also, if possible use the template...
If you could show work it would be greatly appreciated also, if possible use the template that I have provided. Thank you, also this is all the question provides me with. SallyMay, Inc., designs and manufactures T-shirts. It sells its T-shirts to brand name clothes retailers in lots of one dozen. SallyMay's May 2013 static budget and actual results for direct inputs are as follows: Static Budget Number of T-shirt lots (1 lot1 dozen) 400 Per Lot of T-shirts: Direct...
If somebody could assist me with the following questions, that would be greatly appreciated! Thank you!...
If somebody could assist me with the following questions, that would be greatly appreciated! Thank you! 1. How can fluorescence be used to determine the concentration of a molecule? 2. Fluorescence and absorbance comparison (energy, wavelengths)? 3. Why and how we can determine quinine concentration? (include wavelengths used) 4. Why is the detector in a fluorometer placed at a specific angle to the incident beam?
Having some trouble with this python question. An answer would be greatly appreciated! #Write a function...
Having some trouble with this python question. An answer would be greatly appreciated! #Write a function called are_anagrams. The function should #have two parameters, a pair of strings. The function should #return True if the strings are anagrams of one another, #False if they are not. # #Two strings are considered anagrams if they have only the #same letters, as well as the same count of each letter. For #this problem, you should ignore spaces and capitalization. # #So, for...
Please answer the following in regard to Varicella Zoster, sources/references would be greatly appreciated. TIA Varicella...
Please answer the following in regard to Varicella Zoster, sources/references would be greatly appreciated. TIA Varicella Zoster is caused by? Varicella Zoster is identified by the following characteristics: Incubation period: Symptoms: Following the presentation of patients with symptoms indicative of Varicella Zoster diagnosis may be made through: Treatments may include: Preventative methods for preventing the growth and establishment of Varicella Zoster Carriers Transmission Epidemiology Prevalence Target population: Susceptibility Current Research:
If you could show all your work it would be greatly appreciated! Sportz, Inc., manufactures athletic...
If you could show all your work it would be greatly appreciated! Sportz, Inc., manufactures athletic shoes and athletic clothing for both amateur and professional athletes. The company has two product lines (clothing and shoes), which are produced in separate manufacturing facilities; however, both manufacturing facilities share the same support services for information technology and human resources. The following shows total costs for each manufacturing facility and for each support department. Variable Cost Fixed Cost Total Costs by Department Information...
Examples for each of those would be greatly appreciated, thank you! How do heat engines work?...
Examples for each of those would be greatly appreciated, thank you! How do heat engines work? What does a coefficient of performance mean for the engine and the different types of efficiencies? What does it mean if the engine is reversible or impossible [How to determine this]?
If you could answer all 4 that would be greatly appreciated, thanks 1. Hull Company reported...
If you could answer all 4 that would be greatly appreciated, thanks 1. Hull Company reported the following income statement information for the current year: Sales $ 413,000 Cost of goods sold: Beginning inventory $ 136,500 Cost of goods purchased 276,000 Cost of goods available for sale 412,500 Ending inventory 147,000 Cost of goods sold 265,500 Gross profit $ 147,500 The beginning inventory balance is correct. However, the ending inventory figure was overstated by $23,000. Given this information, the correct...
Keep getting error where the code cannot read the text file and create an arraylist of...
Keep getting error where the code cannot read the text file and create an arraylist of objects from it. HouseListTester: import java.util.*; //Hard codes the criteria public class HouseListTester { static HouseList availableHouses; public static void main(String []args) { availableHouses = new HouseList("C:\\Users\\jvs34\\Downloads\\houses.txt"); Criteria c1 = new Criteria(1000, 500000, 100, 5000, 0, 10); Criteria c2 = new Criteria(1000, 100000, 500, 1200, 0, 3); Criteria c3 = new Criteria(100000, 200000, 1000, 2000, 2, 3); Criteria c4 = new Criteria(200000, 300000, 1500,...
There is error in this java code. Pls debug. // Prompt user for value to start...
There is error in this java code. Pls debug. // Prompt user for value to start // Value must be between 1 and 20 inclusive // At command line, count down to blastoff // With a brief pause between each displayed value import java.util.*; public class DebugSix3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String userNumString; int userNum, val; final int MIN = 1; final int MAX = 20; System.out.println("Enter a number between " +...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT