Пример #1
0
 /*setup the game */
 private void setup() {
   t0 = System.currentTimeMillis(); /*Times the beginning of the game */
   // int size;
   Scanner in = new Scanner(System.in);
   // System.out.println("Enter the size of available");
   // size = in.nextInt();
   initiateScores();
   placeWalls();
   placeStates();
   placeLabels();
   randomizeOrderRent(); /*randomizes the order of the equipment for the On Rent state */
   System.out.println(
       "How many High Runners at price $" + EQUIPMENTCOSTS[0] + " do you want to buy?");
   int type1Equip = in.nextInt();
   System.out.println(
       "How many Medium Runners at price $" + EQUIPMENTCOSTS[1] + " do you want to buy?");
   int type2Equip = in.nextInt();
   System.out.println(
       "How many Low Runners at price $" + EQUIPMENTCOSTS[2] + " do you want to buy?");
   int type3Equip = in.nextInt();
   capitalInvested =
       EQUIPMENTCOSTS[0] * type1Equip
           + EQUIPMENTCOSTS[1] * type2Equip
           + EQUIPMENTCOSTS[2] * type3Equip;
   capitalLabel.setLabel("Capital Invested: $" + capitalInvested);
   fillAvailable(type1Equip, type2Equip, type3Equip); // fills with the proper number of equipment
   // fillStates(size,INITRENT,INITSHOP);
   placeEquipments();
 }
Пример #2
0
 public CartesianPanel() {
   double data[];
   Scanner in = new Scanner(System.in);
   int rangeAtas[];
   int rangeBawah[];
   xCoordNumbers = in.nextInt();
   int variabelLinguistik = in.nextInt();
   std = new double[variabelLinguistik];
   sig = new int[variabelLinguistik];
   nilaiAwal = new int[variabelLinguistik];
   nilaiAkhir = new int[variabelLinguistik];
   int temp = 0;
   while (temp < variabelLinguistik) {
     int n = in.nextInt();
     data = new double[n];
     int t = 0;
     while (t < n) {
       data[t] = in.nextDouble();
       t++;
     }
     nilaiAwal[temp] = in.nextInt();
     nilaiAkhir[temp] = in.nextInt();
     std[temp] = findSTDEV(data);
     sig[temp] = (int) (nilaiAkhir[temp] + nilaiAwal[temp]) / 2;
     // System.out.println(nilaiAwal[temp]+" "+nilaiAkhir[temp]+" "+std[temp]+" "+sig[temp]);
     temp++;
   }
   this.alfa = in.nextDouble();
   // this.alfa = alfa;
   // this.xCoordNumbers = nilaiAkhir[temp-1];
   // this.nilaiAwal = rangeAtas;
   // System.out.println(alfa);
   this.jumlahGrafik = variabelLinguistik;
 }
Пример #3
0
  public Map loadMap(File input) throws FileNotFoundException {
    Scanner s = new Scanner(input);
    tileDir = s.nextLine();
    int width = s.nextInt();
    int height = s.nextInt();
    Map toReturn = new Map(width, height, tileDir);
    s.nextLine(); // eat up rest of line.
    for (int y = 0; y < height; y++) {
      String line = s.nextLine();
      Scanner lineReader = new Scanner(line);
      List<Tile> tList = new ArrayList<Tile>();
      for (int x = 0; x < width; x++) {
        String[] values = lineReader.next().split("/");
        String name = values[0];
        int[] picLocation = new int[2];
        for (int i = 0; i < picLocation.length; i++) {
          picLocation[i] = Integer.parseInt(values[1].split("_")[i]);
        }
        ImageIcon img = null;
        try {
          img = new ImageIcon(getTile(tileDir, picLocation[0], picLocation[1], DISPLAY_SCALE));
        } catch (IOException e) {
          System.out.println("Could not find image.");
          img =
              new ImageIcon(
                  new BufferedImage(
                      TILE_SIZE * DISPLAY_SCALE,
                      TILE_SIZE * DISPLAY_SCALE,
                      BufferedImage.TYPE_INT_RGB));
        }
        int avoid = Integer.parseInt(values[2]);
        int def = Integer.parseInt(values[3]);
        String[] movString = values[4].split(",");
        int[] moveCost = new int[movString.length];
        for (int i = 0; i < moveCost.length; i++) {
          moveCost[i] = Integer.parseInt(movString[i]);
        }
        String special = values[5];

        Tile t =
            new Tile(
                img,
                name,
                avoid,
                def,
                moveCost,
                special,
                true,
                "" + picLocation[0] + "_" + picLocation[1]);
        tList.add(t);
        t.setMaximumSize(new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
        t.setPreferredSize(new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
        t.addMouseListener(new MapButtonListener());
      }
      toReturn.addRow(tList);
    }
    return toReturn;
  }
Пример #4
0
  // experimental
  // ====================================================================
  // ====================================================================
  // ====================================================================
  private void readAndDrawBIGGraph(String file) {
    // behövs inte än
    // @TODO
    // hur rita flera linjer mellan 2 noder? (för flera linjer)
    // reading of the graph should be done in the graph itself
    // it should be possible to get an iterator over nodes and one over edges
    // read in all the stops and lines and draw the lmap
    Scanner indata = null;
    // insert into p-queue to get them sorted
    names = new PriorityQueue<String>();
    try {
      // Read stops and put them in the node-table
      // in order to give the user a list of possible stops
      // assume input file is correct
      indata = new Scanner(new File(file + "-stops.txt"), "ISO-8859"); //
      while (indata.hasNext()) {
        String hpl = indata.next().trim();
        int xco = indata.nextInt();
        int yco = indata.nextInt();
        noderna.add(new BusStop(hpl, xco, yco));
        names.add(hpl);
        // Draw
        // this is a fix: fixa att Kålltorp och Torp är samma hållplats
        if (hpl.equals("Torp")) {
          xco += 11;
          hpl = "   / Torp";
        }
        karta.drawString(hpl, xco, yco, DrawGraph.Layer.BASE);
      }
      indata.close();

      //  Read in the lines and add to the graph
      indata = new Scanner(new File(file + "-lines.txt"), "ISO-8859");
      grafen = new DirectedGraph<BusEdge>(noderna.noOfNodes());
      Color color =
          new Color((float) Math.random(), (float) Math.random(), (float) Math.random()); //
      String lineNo = "1"; //
      while (indata.hasNext()) { // assume lines are correct
        int from = noderna.find(indata.next()).getNodeNo();
        int to = noderna.find(indata.next()).getNodeNo();
        grafen.addEdge(new BusEdge(from, to, indata.nextInt(), lineNo));
        indata.nextLine(); // skip rest of line
        // Draw
        BusStop busFrom = noderna.find(from);
        BusStop busTo = noderna.find(to);
        karta.drawLine(
            busFrom.xpos, busFrom.ypos, busTo.xpos, busTo.ypos, color, 2.0f, DrawGraph.Layer.BASE);
      }
      indata.close();
    } catch (FileNotFoundException fnfe) {
      throw new RuntimeException(" Indata till busshållplatserna saknas");
    }
    karta.repaint();
  } // end readAndDrawBIGGraph
Пример #5
0
  public void loadView(String filename) {
    Point3 point;
    Vector3 tvec;
    double radius;
    double azimuth;
    double elevation;
    double scale;
    double x, y, z;
    double vx, vy, vz;

    try {
      if (_ipg == null) throw new Exception("Must load a cube first!");
      Scanner s = new Scanner(new File(filename));
      radius = s.nextDouble();
      x = s.nextDouble();
      y = s.nextDouble();
      z = s.nextDouble();
      point = new Point3(x, y, z);
      azimuth = s.nextDouble();
      elevation = s.nextDouble();
      scale = s.nextDouble();
      vx = s.nextDouble();
      vy = s.nextDouble();
      vz = s.nextDouble();
      tvec = new Vector3(vx, vy, vz);
      Iterator<ImagePanel> itr = _ipg.getImagePanels();
      while (itr.hasNext()) {
        ImagePanel ip = itr.next();
        AxisAlignedFrame aaf = ip.getFrame();
        double lx = s.nextDouble();
        double ly = s.nextDouble();
        double lz = s.nextDouble();
        double mx = s.nextDouble();
        double my = s.nextDouble();
        double mz = s.nextDouble();

        Point3 min = new Point3(lx, ly, lz);
        Point3 max = new Point3(mx, my, mz);
        aaf.setCorners(min, max);
      }
      _pmax = s.nextFloat();
      int code = s.nextInt();
      _color = ColorList.getMatch(code);
      setColorMap();
      _view.setWorldSphere(new BoundingSphere(point, radius));
      _view.setTranslate(tvec);
      _view.setAzimuth(azimuth);
      _view.setElevation(elevation);
      _view.setScale(scale);
      _ipg.setPercentiles(_pmin, _pmax);

    } catch (Exception e) {
      System.out.println("Failed to load view point!");
      System.out.println(e);
    }
  }
Пример #6
0
  public void readFile() throws IOException, FileNotFoundException {
    Scanner inp = new Scanner(System.in);
    System.out.print("Enter the name of the file to process:  ");
    String file;
    file = inp.nextLine();
    System.out.println(file);
    Scanner fileScan = new Scanner(new FileReader(file));
    fileScan.useDelimiter(",");

    numBars = fileScan.nextInt();
    values = new int[numBars];
    labels = new String[numBars];
    for (int i = 0; i < numBars - 1; i++) {
      values[i] = fileScan.nextInt();
      labels[i] = fileScan.next();
      System.out.println(values[i] + " " + labels[i]);
    }
    inp.close();
    fileScan.close();
  }
Пример #7
0
 public static void main(String[] args) {
   int a, b, c;
   Scanner reader = new Scanner(System.in);
   System.out.print("请输入两个整数:");
   a = reader.nextInt();
   b = reader.nextInt();
   GcdLcm o = new GcdLcm();
   c = o.getGcd(a, b);
   System.out.println("gcd(" + a + "," + b + ")=" + c);
   System.out.println("lcm(" + a + "," + b + ")=" + (a * b) / c);
 }
Пример #8
0
 public static void bars(DrawingPanel panel, String nameInfo) {
   Graphics g = panel.getGraphics();
   Scanner s = new Scanner(nameInfo);
   s.next(); // skips name
   String gender = s.next();
   for (int i = startYear; i <= 2010; i += 10) {
     g.setColor(Color.BLACK);
     int rank = s.nextInt();
     int x = ((decadeWidth / 10) * (i - startYear));
     int y = 30 + (rank / 2);
     if (rank == 0) y = 560 - bannerHeight;
     g.drawString("" + rank, x, y);
     if (gender.equals("f")) g.setColor(Color.pink);
     else g.setColor(Color.blue);
     g.fillRect(x, y, decadeWidth / 2, 560 - bannerHeight - y);
   }
   s.close();
 }
Пример #9
0
  // main(): application entry point
  public void disp(String args) {
    // set up scanner
    Scanner scan = new Scanner(System.in);

    // display program's purpose
    System.out.println(
        "This program will draw a Sierpinski Fractal to the user's specified depth.\n");

    // determine desired cycles and color
    System.out.println(
        "How many cycles would you like the Sierpinski Fractal to be taken out to?\n");
    int a = scan.nextInt();
    System.out.println();

    // produce Sierpinski Fractal
    Point p1 = new Point(50, 50);
    Point p2 = new Point(50, 450);
    Point p3 = new Point(450, 50);
    // Color c =new
    // Color((int)((Math.random()*20000)%256),(int)((Math.random()*10000)%256),(int)((Math.random()*30000)%256));
    Color c = Color.BLACK;
    JFrame window = new JFrame("Sierpinski Fractal-" + a + ".");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setSize(500, 500);
    window.setVisible(true);

    Graphics g = window.getGraphics();
    Graphics2D g2d = (Graphics2D) g;
    // Container con=getContentPane();
    // con.setBackground(Color.BLACK);

    // g2d.setBackground(Color.BLACK);
    System.out.println("\nEnter any character when ready.\n");
    Scanner stdin = new Scanner(System.in);
    stdin.nextLine();

    Sierpinski(g, p1, p2, p3, c, a);
    System.out.println("\nEnter any character if you wish to exit!\n");
    stdin = new Scanner(System.in);
    stdin.nextLine();
    System.exit(0);
  }
Пример #10
0
  public void parseInput(String file, int threads, int limit)
      throws FileNotFoundException, InterruptedException {
    // long startParseTime = System.currentTimeMillis();
    m_jgAdapter = new JGraphModelAdapter<Position, DefaultEdge>(graph);
    jgraph = new JGraph(m_jgAdapter);
    this.threads = threads;

    Scanner input = new Scanner(new File(file));
    try {
      for (int r = 0; input.hasNextLine() && r < limit; r++) {
        Scanner line = new Scanner(input.nextLine());
        try {

          ArrayList<Position> row = new ArrayList<Position>();
          grid.add(row);

          System.out.println("Row " + r);

          for (int c = 0; line.hasNextInt() && c < limit; c++) {
            Position position = new Position(r, c, line.nextInt());
            row.add(position);
            graph.addVertex(position);
            positionVertexAt(position, position.column * 5, position.row * 5);
          }
        } finally {
          line.close();
        }
      }
    } finally {
      input.close();
    }

    graphGrid(grid);

    // ArrayList<ArrayList<Position>> grid2 = transpose(grid);
    // outputGrid(grid2);

  }
Пример #11
0
 /**
  * Allows input of an int (integer) from the keyboard in a text window. <br>
  * Example: <br>
  * System.out.print("How old are you? --> "); <br>
  * int age = Expo.enterInt();
  */
 public static int enterInt() {
   Scanner input = new Scanner(System.in);
   int temp = input.nextInt();
   return temp;
 }
Пример #12
0
  // ====================================================================
  // ====================================================================
  private void readAndDrawGraph() {
    // @TODO
    // hur rita flera linjer mellan 2 noder? (för flera linjer)
    // reading of the graph should be done in the graph itself
    // it should be possible to get an iterator over nodes and one over edges
    // read in all the stops and lines and draw the lmap
    Scanner indata = null;
    // insert into p-queue to get them sorted
    names = new PriorityQueue<String>();
    try {
      // Read stops and put them in the node-table
      // in order to give the user a list of possible stops
      // assume input file is correct
      indata = new Scanner(new File("stops.noBOM.txt"), "UTF-8");
      while (indata.hasNext()) {
        String hpl = indata.next().trim();
        int xco = indata.nextInt();
        int yco = indata.nextInt();
        noderna.add(new BusStop(hpl, xco, yco));
        names.add(hpl);
        // Draw
        /*
        // Denna fix som slår ihop Kålltorp och Torp är förvirrande eftersom de är olika noder i grafen.
        // Tror man att det är samma nod blir resultatet förrvirrande.
        // Till nästa gång: Gör till samma nod med namnet Virginsgatan. Så är det i verkligheten nu.

        				// this is a fix: fixa att Kålltorp och Torp är samma hållplats
        				if ( hpl.equals("Torp") ) {
        					xco += 11;
        					hpl = "   / Torp";
        				}
        */
        karta.drawString(hpl, xco, yco, DrawGraph.Layer.BASE);
      }
      indata.close();

      //  Read in the lines and add to the graph
      indata = new Scanner(new File("lines.noBOM.txt"), "UTF-8");
      grafen = new DirectedGraph<BusEdge>(noderna.noOfNodes());
      while (indata.hasNext()) {
        String lineNo = indata.next();
        int antal = indata.nextInt() - 1;
        int from = noderna.find(indata.next()).getNodeNo();
        // hur rita flera linjer mellan 2 noder?
        // enkel inc fungerar inte
        // färgen kunde vara "äkta" dvs linjefärg
        Color color =
            new Color((float) Math.random(), (float) Math.random(), (float) Math.random());
        for (int i = 0; i < antal; i++) {
          int to = noderna.find(indata.next()).getNodeNo();
          grafen.addEdge(new BusEdge(from, to, indata.nextInt(), lineNo));
          // Draw
          BusStop busFrom = noderna.find(from);
          BusStop busTo = noderna.find(to);
          karta.drawLine(
              busFrom.xpos,
              busFrom.ypos,
              busTo.xpos,
              busTo.ypos,
              color,
              2.0f,
              DrawGraph.Layer.BASE);
          from = to;
        }
      }
      indata.close();
    } catch (FileNotFoundException fnfe) {
      throw new RuntimeException(" Indata till busshållplatserna saknas");
    }
    karta.repaint();
  } // end readAndDrawGraph