Advertisement
Guest User

Tumors

a guest
Dec 4th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. package tumors;
  2.  
  3. import java.util.Scanner;
  4. import java.io.IOException;
  5. import java.io.File;
  6.  
  7. public class Tumors {
  8. private int[][] scanned;
  9. private int[][] detect;
  10.  
  11. static Scanner scan = new Scanner(System.in);
  12. static boolean flag = true;
  13.  
  14. public Tumors() throws IOException {
  15.  
  16. scan = new Scanner(new File("Tumors.txt"));
  17.  
  18. int scannedLength = scan.nextInt();
  19. int detectLength = scan.nextInt();
  20.  
  21. scanned = new int[scannedLength][scannedLength];
  22. detect = new int[detectLength][detectLength];
  23.  
  24. // sets up all numbers in the scanned array
  25. for (int i = 0; i < scanned.length; i++) {
  26. for (int j = 0; j < scanned[0].length; j++) {
  27.  
  28. scanned[i][j] = scan.nextInt();
  29. }
  30. }
  31.  
  32. for (int i = 0; i < detect.length; i++) {
  33. for (int j = 0; j < detect[0].length; j++) {
  34.  
  35. detect[i][j] = scan.nextInt();
  36. }
  37. }
  38. }
  39.  
  40. public void printScan() {
  41.  
  42. System.out.println("The scan is as follows: ");
  43.  
  44. for (int i = 0; i < scanned.length; i++) {
  45. for (int j = 0; j < scanned[0].length; j++) {
  46. if (scanned[i][j] == 1) {
  47. System.out.print("+");
  48. } else {
  49. System.out.print("_");
  50. }
  51. }
  52. System.out.println();
  53. }
  54. }
  55.  
  56. public void printTumorPossibility() {
  57.  
  58. System.out.println("\nThe tumor possibility is as follows: ");
  59.  
  60. for (int i = 0; i < detect.length; i++) {
  61. for (int j = 0; j < detect[0].length; j++) {
  62. if (detect[i][j] == 1) {
  63. System.out.print("+");
  64. } else {
  65. System.out.print("_");
  66. }
  67. }
  68. System.out.println();
  69. }
  70.  
  71. }
  72.  
  73. public void checkTumorPossibilities() {
  74.  
  75. int[][] segmentOfScan = new int[detect.length][detect[0].length];
  76.  
  77. boolean isTumor = false;
  78.  
  79. for (int scoot = 0; scoot < scanned.length; scoot++) {
  80. for (int i = 0; i < detect.length; i++) {
  81. for (int j = 0; j < detect.length; j++) {
  82.  
  83. segmentOfScan[i][j] = scanned[i + scoot][j + scoot];
  84.  
  85. }
  86. isTumor = check(segmentOfScan);
  87. if(isTumor){
  88. System.out.println("THERE IS A TUMOR!!!!!");
  89. }
  90. }
  91. }
  92.  
  93. }
  94.  
  95. public boolean check(int[][] arr){
  96.  
  97.  
  98. for(int i = 0; i<arr.length; i++){
  99. for(int j = 0; j < arr[0].length; j++){
  100.  
  101. if(arr[i][j] != detect[i][j]){
  102. return false;
  103. }
  104. }
  105. }
  106. return true;
  107.  
  108. }
  109.  
  110.  
  111.  
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement