Hello all very advanced programmers.

I'm a amateur programmer still learning to climb the ropes. I am trying to run a certain program on Java but seem to get some errors that does not define itself any further.

These are the errors I am currently getting when I compile the program:

BrownianZombies.java:183: cannot resolve symbol
symbol : class Scanner
location: class BrownianZombies
static Scanner input;
^
BrownianZombies.java:217: cannot resolve symbol
symbol : class Scanner
location: class BrownianZombies
input = new Scanner(pr.getInputStream());
^
2 errors

What I did is I commented these two lines out, and try compiling again. Another error:

BrownianZombies.java:95: cannot resolve symbol
symbol : variable input
location: class BrownianZombies
String dir = input.next();
^
1 error

With this line I could not comment out, because there was a whole lot other variables to consider. So, I changed the above to String dir = "";

I am working with J2SDK 1.4.1_04.

Any ideas?

I've attached the program I'm working with, it is actually from another site. I'm just trying to run it to get an idea of what is required.

Ronica

Attachments
import java.util.*;
import javax.swing.*;
import java.io.*;
import java.security.*;
import java.awt.*;
import java.awt.event.*;

public class BrownianZombies extends JFrame{
    int[] zx, zy;
    int x, y;
    int[] idx;
    boolean[][] visited;
    double p;
    Random r;
    int delay = 100;
    boolean novis, history;
    void generate(String seed){
        try{
            r = SecureRandom.getInstance("SHA1PRNG");
            r.setSeed(Integer.parseInt(seed));
        } catch (Exception e) {   
            e.printStackTrace();
        }
        int[] tx = new int[10000];
        int[] ty = new int[10000];
        idx = new int[10000];
        visited = new boolean[100][100];
        int ptr = 0;
        p = r.nextDouble()*0.1+0.05;
        for(int i = 0; i<idx.length; i++)idx[i] = i;

        for(int i = 0; i<100; i++)for(int j = 0; j<100; j++){
            if(i >= 5 || j >= 5)if(r.nextDouble() < p){
                tx[ptr] = i;
                ty[ptr] = j;
                ptr++;
            }
        }
        zx = new int[ptr];
        zy = new int[ptr];
        for(int i = 0 ;i<ptr; i++){
            zx[i] = tx[i];
            zy[i] = ty[i];
        }

    }
    public void move(){
        for(int i = 0; i<zx.length; i++){
            int s = r.nextInt(i+1);
            int t = idx[i];idx[i] = idx[s];idx[s] = t;
        }
        for(int i = 0; i<zx.length; i++){
            int xx = zx[idx[i]] + r.nextInt(3) - 1;
            int yy = zy[idx[i]] + r.nextInt(3) - 1;
            if(xx < 100 && yy < 100 && xx >= 0 && yy >= 0){
                zx[idx[i]] = xx;
                zy[idx[i]] = yy;
            }
        }
    }

    int lives = 10;
    int T;
    public boolean ok(){
        for(int i = 0; i<zx.length; i++)if(x == zx[i] && y == zy[i])lives--;
        return lives >= 0;
    }

    public String checkData(String s){return "";}
    public double runTest(String lt){
        try{
            
            int time = 10000;
            generate(lt);
            StringBuffer sb = new StringBuffer();
            sb.append(zx.length).append('\n');
            os.write(sb.toString().getBytes());
            os.flush();
            int score = 30000; T = 0;
            if(history)visited[0][0] = true;
            while((x != 99 || y != 99) && T < 10000){
                T++;
                sb.delete(0,sb.length());
                sb.append(zx[0]);
                for(int i = 1; i<zx.length; i++)
                    sb.append(' ').append(zx[i]);
                sb.append('\n');
                sb.append(zy[0]);
                for(int i = 1; i<zy.length; i++)
                    sb.append(' ').append(zy[i]);
                sb.append('\n').append(x).append(' ').append(y).append('\n');
                os.write(sb.toString().getBytes());
                os.flush();

                String dir = input.next();
		String dir = "";
                if(dir.equals("S")){
                }else if(dir.equals("R")){
                    x++;
                }else if(dir.equals("L")){
                    x--;
                }else if(dir.equals("U")){
                    y--;
                }else if(dir.equals("D")){
                    y++;
                }else if(dir.equals("RU")){
                    x++;
                    y--;
                }else if(dir.equals("LU")){
                    x--;
                    y--;
                }else if(dir.equals("RD")){
                    x++;
                    y++;
                }else if(dir.equals("LD")){
                    x--;
                    y++;
                }else{
                    System.out.println("Invalid Direction: "+dir);
                    return 0;
                }
                if(x < 0)x = 0;
                if(y < 0)y = 0;
                if(x == 100)x = 99;
                if(y == 100)y = 99;
                if(!ok()){
                    System.out.println("Brains... Score = "+T);
                    return T;
                }
                move();
                if(!ok()){
                    System.out.println("Brains... Score = "+T);
                    return T;
                }
                score -= 2;
                if(!novis){
                    if(history)visited[x][y] = true;
                    repaint();
                    Thread.sleep(delay);
                }
            }
            System.out.println("Score: "+(score + lives * 1000));
            return score + (x != 99 || y != 99 ? 0 : lives * 1000);
        }catch(Exception e){
            e.printStackTrace();
            return 0;
        }
    }
    class Vis extends JPanel{
        public void paint(Graphics g){
            if(zx == null)return;
            Graphics2D g2 = (Graphics2D)g;
            g2.setColor(new Color(200,200,200));
            g2.fillRect(0,0,getWidth(),getHeight());
            Font f = new Font(g2.getFont().getName(),Font.PLAIN,20);
            g2.setFont(f);
            FontMetrics fm = g2.getFontMetrics();
            int th = fm.getAscent();
            int mul = Math.max(1,Math.min((getWidth()-1)/100,(getHeight()-1-2*th)/100));
            int[][] cnt = new int[100][100];
            for(int i = 0; i<zx.length; i++){
                cnt[zx[i]][zy[i]]++;
            }
            for(int i = 0; i<100; i++){
                for(int j = 0; j<100; j++){
                    if(cnt[i][j] == 1)g.setColor(Color.red);
                    else if(cnt[i][j] > 1)g.setColor(Color.magenta);
                    else if(visited[i][j])g.setColor(Color.cyan);
                    else g.setColor(Color.white);
                    if(i == x && j == y)g.setColor(Color.blue);
                    g.fillRect(mul*i+1,2*th+mul*j+1,mul,mul);
                }
            }
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            String txt = "Moves Made: "+T;
            g.setColor(Color.black);
            g.drawString(txt,0,th);
            txt = "Lives left : "+lives;
            g.drawString(txt,0,2*th);
        }
    }
    static Process pr;
    static Scanner input;
    static InputStream error;
    static DataOutputStream os;
    public static void main(String[] args) throws IOException{
        BrownianZombies b = new BrownianZombies();
        String exec = null;
        String seed = "1";
        for(int i = 0; i<args.length; i++){
            if(args[i].equals("-delay")){
                b.delay = Integer.parseInt(args[++i]);
            }else if(args[i].equals("-seed")){
                seed = args[++i];
            }else if(args[i].equals("-novis")){
                b.novis = true;
            }else if(args[i].equals("-history")){
                b.history = true;
            }else{
                exec = args[i];
            }
        }
        if(exec == null){
            System.out.println("Please enter an executable");
            System.exit(1);
        }
        //for(int i = 0; i<b.zx.length; i++){
            //System.out.println(i+" "+b.zx[i]+" "+b.zy[i]);
        //}
        if(!b.novis){
            b.add(b.new Vis());
            b.setSize(450,450);
            b.setVisible(true);
            b.addWindowListener(new Closer());
        }
        pr = Runtime.getRuntime().exec(args[0]);
        input = new Scanner(pr.getInputStream());
        error = pr.getErrorStream();
        os = new DataOutputStream(pr.getOutputStream());

        new ErrorReader().start();
        b.runTest(seed);
        pr.destroy();
    }
    public String displayTestCase(String s){
        generate(s);
        return "p = "+p;
    }
    public double[] score(double[][] d){
        double[] ret = new double[d.length];
        for(int i = 0; i<ret.length; i++)
            for(int j = 0; j<d[0].length; j++)
                ret[i] += d[i][j];
        return ret;
    }
    static class ErrorReader extends Thread{
        public void run(){
            try{
                byte[] ch = new byte[50000];
                int read;
                while((read = error.read(ch)) > 0){
                    String s = new String(ch,0,read);
                    //System.out.println("err: "+s+" "+s.endsWith("\n"));
                    System.out.print(s);
                }
                System.out.println();
            }catch(Exception e){
                //System.err.println("Failed to read from stderr");
            }
        }
    }
    static class Closer implements WindowListener{
        public void windowActivated(WindowEvent e){}
        public void windowDeactivated(WindowEvent e){}
        public void windowOpened(WindowEvent e){}
        public void windowClosing(WindowEvent e){ 
            pr.destroy();
            System.exit(0); 
        }
        public void windowClosed(WindowEvent e){}
        public void windowIconified(WindowEvent e) {}
        public void windowDeiconified(WindowEvent e) {}
    }
}

Hi,

IDE, not sure but I use normal notepad as an editor, and Java 2 SDK SE 1.4.1_04 Runtime Environment.

What do you use? Tried on JBuilder as well, still do not know how to get that going.

Did you use any arguments?

i use bluej

no arguments

what is it actually supposed to do, running it it asked for an executable, what should i pass?

this is what you are trying to compile:

import java.util.*;
import javax.swing.*;
import java.io.*;
import java.security.*;
import java.awt.*;
import java.awt.event.*;

public class BrownianZombies extends JFrame{
    int[] zx, zy;
    int x, y;
    int[] idx;
    boolean[][] visited;
    double p;
    Random r;
    int delay = 100;
    boolean novis, history;
    void generate(String seed){
        try{
            r = SecureRandom.getInstance("SHA1PRNG");
            r.setSeed(Integer.parseInt(seed));
        } catch (Exception e) {   
            e.printStackTrace();
        }
        int[] tx = new int[10000];
        int[] ty = new int[10000];
        idx = new int[10000];
        visited = new boolean[100][100];
        int ptr = 0;
        p = r.nextDouble()*0.1+0.05;
        for(int i = 0; i<idx.length; i++)idx[i] = i;

        for(int i = 0; i<100; i++)for(int j = 0; j<100; j++){
            if(i >= 5 || j >= 5)if(r.nextDouble() < p){
                tx[ptr] = i;
                ty[ptr] = j;
                ptr++;
            }
        }
        zx = new int[ptr];
        zy = new int[ptr];
        for(int i = 0 ;i<ptr; i++){
            zx[i] = tx[i];
            zy[i] = ty[i];
        }

    }
    public void move(){
        for(int i = 0; i<zx.length; i++){
            int s = r.nextInt(i+1);
            int t = idx[i];idx[i] = idx[s];idx[s] = t;
        }
        for(int i = 0; i<zx.length; i++){
            int xx = zx[idx[i]] + r.nextInt(3) - 1;
            int yy = zy[idx[i]] + r.nextInt(3) - 1;
            if(xx < 100 && yy < 100 && xx >= 0 && yy >= 0){
                zx[idx[i]] = xx;
                zy[idx[i]] = yy;
            }
        }
    }

    int lives = 10;
    int T;
    public boolean ok(){
        for(int i = 0; i<zx.length; i++)if(x == zx[i] && y == zy[i])lives--;
        return lives >= 0;
    }

    public String checkData(String s){return "";}
    public double runTest(String lt){
        try{
            
            int time = 10000;
            generate(lt);
            StringBuffer sb = new StringBuffer();
            sb.append(zx.length).append('\n');
            os.write(sb.toString().getBytes());
            os.flush();
            int score = 30000; T = 0;
            if(history)visited[0][0] = true;
            while((x != 99 || y != 99) && T < 10000){
                T++;
                sb.delete(0,sb.length());
                sb.append(zx[0]);
                for(int i = 1; i<zx.length; i++)
                    sb.append(' ').append(zx[i]);
                sb.append('\n');
                sb.append(zy[0]);
                for(int i = 1; i<zy.length; i++)
                    sb.append(' ').append(zy[i]);
                sb.append('\n').append(x).append(' ').append(y).append('\n');
                os.write(sb.toString().getBytes());
                os.flush();

                String dir = input.next();
		        if(dir.equals("S")){
                }else if(dir.equals("R")){
                    x++;
                }else if(dir.equals("L")){
                    x--;
                }else if(dir.equals("U")){
                    y--;
                }else if(dir.equals("D")){
                    y++;
                }else if(dir.equals("RU")){
                    x++;
                    y--;
                }else if(dir.equals("LU")){
                    x--;
                    y--;
                }else if(dir.equals("RD")){
                    x++;
                    y++;
                }else if(dir.equals("LD")){
                    x--;
                    y++;
                }else{
                    System.out.println("Invalid Direction: "+dir);
                    return 0;
                }
                if(x < 0)x = 0;
                if(y < 0)y = 0;
                if(x == 100)x = 99;
                if(y == 100)y = 99;
                if(!ok()){
                    System.out.println("Brains... Score = "+T);
                    return T;
                }
                move();
                if(!ok()){
                    System.out.println("Brains... Score = "+T);
                    return T;
                }
                score -= 2;
                if(!novis){
                    if(history)visited[x][y] = true;
                    repaint();
                    Thread.sleep(delay);
                }
            }
            System.out.println("Score: "+(score + lives * 1000));
            return score + (x != 99 || y != 99 ? 0 : lives * 1000);
        }catch(Exception e){
            e.printStackTrace();
            return 0;
        }
    }
    class Vis extends JPanel{
        public void paint(Graphics g){
            if(zx == null)return;
            Graphics2D g2 = (Graphics2D)g;
            g2.setColor(new Color(200,200,200));
            g2.fillRect(0,0,getWidth(),getHeight());
            Font f = new Font(g2.getFont().getName(),Font.PLAIN,20);
            g2.setFont(f);
            FontMetrics fm = g2.getFontMetrics();
            int th = fm.getAscent();
            int mul = Math.max(1,Math.min((getWidth()-1)/100,(getHeight()-1-2*th)/100));
            int[][] cnt = new int[100][100];
            for(int i = 0; i<zx.length; i++){
                cnt[zx[i]][zy[i]]++;
            }
            for(int i = 0; i<100; i++){
                for(int j = 0; j<100; j++){
                    if(cnt[i][j] == 1)g.setColor(Color.red);
                    else if(cnt[i][j] > 1)g.setColor(Color.magenta);
                    else if(visited[i][j])g.setColor(Color.cyan);
                    else g.setColor(Color.white);
                    if(i == x && j == y)g.setColor(Color.blue);
                    g.fillRect(mul*i+1,2*th+mul*j+1,mul,mul);
                }
            }
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            String txt = "Moves Made: "+T;
            g.setColor(Color.black);
            g.drawString(txt,0,th);
            txt = "Lives left : "+lives;
            g.drawString(txt,0,2*th);
        }
    }
    static Process pr;
    static Scanner input;
    static InputStream error;
    static DataOutputStream os;
    public static void main(String[] args) throws IOException{
        BrownianZombies b = new BrownianZombies();
        String exec = null;
        String seed = "1";
        for(int i = 0; i<args.length; i++){
            if(args[i].equals("-delay")){
                b.delay = Integer.parseInt(args[++i]);
            }else if(args[i].equals("-seed")){
                seed = args[++i];
            }else if(args[i].equals("-novis")){
                b.novis = true;
            }else if(args[i].equals("-history")){
                b.history = true;
            }else{
                exec = args[i];
            }
        }
        if(exec == null){
            System.out.println("Please enter an executable");
            System.exit(1);
        }
        //for(int i = 0; i<b.zx.length; i++){
            //System.out.println(i+" "+b.zx[i]+" "+b.zy[i]);
        //}
        if(!b.novis){
            b.add(b.new Vis());
            b.setSize(450,450);
            b.setVisible(true);
            b.addWindowListener(new Closer());
        }
        pr = Runtime.getRuntime().exec(args[0]);
        input = new Scanner(pr.getInputStream());
        error = pr.getErrorStream();
        os = new DataOutputStream(pr.getOutputStream());

        new ErrorReader().start();
        b.runTest(seed);
        pr.destroy();
    }
    public String displayTestCase(String s){
        generate(s);
        return "p = "+p;
    }
    public double[] score(double[][] d){
        double[] ret = new double[d.length];
        for(int i = 0; i<ret.length; i++)
            for(int j = 0; j<d[0].length; j++)
                ret[i] += d[i][j];
        return ret;
    }
    static class ErrorReader extends Thread{
        public void run(){
            try{
                byte[] ch = new byte[50000];
                int read;
                while((read = error.read(ch)) > 0){
                    String s = new String(ch,0,read);
                    //System.out.println("err: "+s+" "+s.endsWith("\n"));
                    System.out.print(s);
                }
                System.out.println();
            }catch(Exception e){
                //System.err.println("Failed to read from stderr");
            }
        }
    }
    static class Closer implements WindowListener{
        public void windowActivated(WindowEvent e){}
        public void windowDeactivated(WindowEvent e){}
        public void windowOpened(WindowEvent e){}
        public void windowClosing(WindowEvent e){ 
            pr.destroy();
            System.exit(0); 
        }
        public void windowClosed(WindowEvent e){}
        public void windowIconified(WindowEvent e) {}
        public void windowDeiconified(WindowEvent e) {}
    }
}

correct?

This article has been dead for over six months. Start a new discussion instead.