Что именно я должен возвращать в этом коде? - PullRequest
0 голосов
/ 27 марта 2019

Мы создаем программу, которая вернет топографическую карту и покажет пользователю лучший способ навигации по местности без крутых подъемов или спусков.Для файлов, с которыми я работаю, я не уверен, какие максимальные и минимальные значения должны быть возвращены.Назначение в основном завершено, за исключением 3 ошибок, касающихся ожидаемого возвращаемого значения.Я отправил основной код, с которым мы работаем, и включил ссылку на другие файлы, которые профессор дал нам для назначения.

Я пытался вернуть maxValue, вернуть minValue, вернуть max, вернуть min и несколько других комбинаций, но проблема в том, что я не уверен, должен ли я возвращать значение из этого файла MapDataDrawer.java или из одного из двух других файлов, которые мы должны использовать для назначения изпрофессор.

//MapDataDrawer.java
//This is the code that is returning the error
import java.util.*;
import java.io.*;
import java.awt.*;

public class MapDataDrawer
{

  private int[][] grid;

  public MapDataDrawer(String filename, int rows, int cols){
      // initialize grid 
      grid = new int[rows][cols];

      //read the data from the file into the grid
      File dataFile = new File(filename);
      try {
         Scanner dataInput = new Scanner(dataFile);
         for (int i=0; i<rows; i++) {
            for (int j=0; j<cols;j++) {
               grid[i][j] = dataInput.nextInt();

            }
         }

      } catch (Exception e) { e.printStackTrace();}

  }

  /**
   * @return the min value in the entire grid
   */
  public int findMin() {
     // Implement this method
  }
  /**
   * @return the max value in the entire grid
   */
  public int findMax(){
     // Implement this method
  }

  /**
   * @param col the column of the grid to check
   * @return the index of the row with the lowest value in the given col for the grid
   */
  public  int indexOfMinRow(int col){
     //Implement this method

  }

  /**
   * Draws the grid using the given Graphics object.
   * Colors should be grayscale values 0-255, scaled based on min/max values in grid
   */
  public void drawMap(Graphics g){
      int min = findMin();
      int max = findMax();

      for (int i=0; i<480; i++) {
         for (int j=0; j<480; j++) {
            int c = (255 * (grid[i][j] - min)) / (max - min);
            g.setColor(new Color(c, c, c));
            g.fillRect(j, i, 1, 1);
         }
      }
   }

   /**
   * Find a path from West-to-East starting at given row.
   * Choose a foward step out of 3 possible forward locations, using greedy method described in assignment.
   * @return the total change in elevation traveled from West-to-East
   */
  public int drawLowestElevPath(Graphics g, int row){
    int elevChange = 0;
      // Implement this method
      return elevChange;

  }

   private int minOfThree(int a, int b, int c) {
      if ((a > b) && (a > c)) return a;
      if ((b > a) && (b > c)) return b;
      if ((c > a) && (c > b)) return c;
      return 0;
   }

}

Это файлы, представленные профессорами, в которых я не уверен, должен ли я возвращать какое-либо значение из одного из этих файлов или из файла фактической домашней работы (MapDataDrawer.java) https://drive.google.com/drive/folders/1siRoY1K0ngptE2rL-wscXLK8Ct7Qo1hb?usp=sharing

Он также включает топографические данные, которые мы должны использовать.

1 Ответ

0 голосов
/ 27 марта 2019

Как вы заполнили grid:

public int findMin() {
    int min = Integer.MAX_VALUE;
    for (int i = 0; i < grid.length; i++) {
        for (int j = 0; j < grid[i].length; j++) {
           int value = grid[i][j];
           if (value < min) {
               min = value;
           }
        }
     }
     return min;
 }
...