0

I keep getting an error message saying I have an input mismatch. I just can't seem to figure out where the mismatch is happening. Does somebody see what I'm doing wrong? The other question I have is I want to add +1 to the result.x for each item that comes in. I thought I would to that by setting x = 1 at the beginning of my coordinate class but it doesn't work. Is this not the way to do it? Or am I forgetting something? Sorry pretty new to programming so I hope one of you can help!

This is the input: 5,4 4,5 8,7=6,3 3,2 9,6 4,3=7,6=9,8=5,5 7,8 6,5 6,4 I've first add my main class and below it my second class.

package pirate2;
import java.util.Scanner;
import ui.UIAuxiliaryMethods;
import java.io.PrintStream;

class Pirate4 {

    PrintStream out;

    Pirate4() {
        out = new PrintStream(System.out);
    }

    Coordinate readCoordinate(Scanner coordinateInputScanner) {
        Coordinate result = new Coordinate();

        coordinateInputScanner.useDelimiter(" |,");

        while (coordinateInputScanner.hasNext()) {
            result.x = 1 + coordinateInputScanner.nextInt(); // not the right solution for +1
            result.y = coordinateInputScanner.nextInt();

            System.out.println(result.x + "\t" + result.y);
        }

        return result;
    }

    void start() {

        Scanner fileScanner = UIAuxiliaryMethods.askUserForInput().getScanner();

        while (fileScanner.hasNext()) {

            fileScanner.useDelimiter("=");
            String coordinateRowInput = fileScanner.next();
            Scanner coordinateInputScanner = new Scanner(coordinateRowInput);
            readCoordinate(coordinateInputScanner);

        }

    }

    public static void main(String[] argv) {
        new Pirate4().start();
    }
}

package pirate2;

class Coordinate {
    int x;
    int y;

    Coordinate() {
        x = 0;
        y = 0;
    }
}
Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
Zsa_Sza
  • 15
  • 1
  • 6
  • I'd guess your error has nothing to do with adding `1`, and everything with the fact that you check if your input has a next string, and then try to read two integers from it. – azurefrog Nov 15 '19 at 16:35
  • I figured out the problem for the inputmismatch. I needed to added a extra Scanner to break the coordinates. But I still haven't figured out how to solve the +1. Only by adding it in the while loop itself. Do you have any suggestions? – Zsa_Sza Nov 15 '19 at 17:07

0 Answers0