Untitled
unknown
java
6 days ago
5.2 kB
3
Indexable
import java.util.Arrays; public class Nyomozo { public String nev; private String[] gyanusitottak; private int[] nyomok; // Constructors public Nyomozo(String[] gyanusitottak, int[] nyomok) { this.nev = "Columbo"; this.gyanusitottak = Arrays.copyOf(gyanusitottak, gyanusitottak.length); this.nyomok = Arrays.copyOf(nyomok, nyomok.length); } public Nyomozo(String nev, String[] gyanusitottak, int[] nyomok) { this.nev = nev; this.gyanusitottak = Arrays.copyOf(gyanusitottak, gyanusitottak.length); this.nyomok = Arrays.copyOf(nyomok, nyomok.length); } // Getters public String getNev() { return this.nev; } public String[] getGyanusitottak() { return Arrays.copyOf(this.gyanusitottak, this.gyanusitottak.length); } public int[] getNyomok() { return Arrays.copyOf(this.nyomok, this.nyomok.length); } // Setters public void setNev(String nev) { this.nev = nev; } public void setGyanusitottak(String[] gyanusitottak) { this.gyanusitottak = Arrays.copyOf(gyanusitottak, gyanusitottak.length); } public void setNyomok(int[] nyomok) { this.nyomok = Arrays.copyOf(nyomok, nyomok.length); } public boolean nyomotFelhasznal(int index) { if (index < 0 || index >= this.nyomok.length) { return false; } int[] ujNyomok = new int[this.nyomok.length - 1]; for (int i = 0, j = 0; i < this.nyomok.length; i++) { if (i != index) { ujNyomok[j++] = this.nyomok[i]; } } this.nyomok = ujNyomok; return true; } public boolean felmentoBizonyitek(String kit) { int lastIndex = -1; for (int i = gyanusitottak.length - 1; i < 0; i--) { if (this.gyanusitottak[i].equals(kit)) { lastIndex = i; } } if (lastIndex == -1) return false; String[] ujGyanusitottak = new String[this.gyanusitottak.length - 1]; for (int j = 0, k = 0; j < this.gyanusitottak.length; j++) { if (j != lastIndex) { ujGyanusitottak[k++] = this.gyanusitottak[j]; } } this.gyanusitottak = ujGyanusitottak; return true; } public void inditek() { if (this.gyanusitottak.length > 1) { String elso = this.gyanusitottak[0]; System.arraycopy(this.gyanusitottak, 1, this.gyanusitottak, 0, this.gyanusitottak.length - 1); this.gyanusitottak[this.gyanusitottak.length - 1] = elso; } } public void nyomokatRendez() { for (int i = 0; i < this.nyomok.length / 2; i++) { int temp = this.nyomok[i]; this.nyomok[i] = this.nyomok[this.nyomok.length - 1 - i]; this.nyomok[this.nyomok.length - 1 - i] = temp; } } public void alibikEliminalasa() { if (this.nyomok.length < 3) return; int ujMeret = this.nyomok.length - (this.nyomok.length / 3); int[] ujNyomok = new int[ujMeret]; for (int i = 0, j = 0; i < this.nyomok.length; i++) { if ((i + 1) % 3 != 0) { ujNyomok[j++] = this.nyomok[i]; } } this.nyomok = ujNyomok; } public boolean bajbanVan() { for (int i = 0; i < this.nyomok.length; i++) { if (this.nyomok[i] == 1) { if (nyomotFelhasznal(i) && felmentoBizonyitek(this.nev)) { return true; } } } return false; } public String nyomozas() { if (this.gyanusitottak.length == 0) { return "Sajnos az ügy megoldatlan, nincs gyanúsított"; } while (this.nyomok.length > 0) { if (this.gyanusitottak.length == 1) { return "Az ügy megoldva, a bűnös: " + this.gyanusitottak[0]; } if (this.gyanusitottak[0].equals(this.nev) && bajbanVan()) { continue; } int jelenlegiNyom = this.nyomok[0]; nyomotFelhasznal(0); switch (jelenlegiNyom) { case 1: felmentoBizonyitek(this.gyanusitottak[0]); break; case 2: inditek(); break; case 3: nyomokatRendez(); break; case 4: alibikEliminalasa(); break; case 5: if (this.nyomok.length > 0) { nyomotFelhasznal(0); } break; } } if (this.gyanusitottak.length > 1) { return "Nincs elég nyom, a megmaradt gyanúsítottak: " + String.join(" ", this.gyanusitottak); } return "Az ügy megoldva, a bűnös: " + this.gyanusitottak[0]; } }
Editor is loading...
Leave a Comment