Új hozzászólás Aktív témák
-
Regirck
senior tag
Sziasztok!
Kérnék szépen egy kis segítséget!
Az alábbi program kódba..., tanulom a Jáva programnyelvet de most kicsit elakadtam.
Azt szeretném elérni, hogy ha döntettlenre jön ki a dobás akkor kezdje előről a a programfutást. Sehogy se tudom "returnolni".
Tudomnem egy "CleanCode", de az alapok megértésén vagyok.
package tester;
public class Tester {
public static void main(String[] args) {
Engine start = new Engine();
start.Dice();
System.out.println("");
if ("You".equals(start.toString())) {
System.out.println("Nyertél!");
} else if ("Computer".equals(start.toString())) {
System.out.println("Vesztettél!");
} else {
System.out.println("Döntettlen!");
}
}
}package tester;
import java.util.Random;
public class Engine {
@Override
public String toString() {
if (You > Computer) {
return "You";
} else if (Computer > You) {
return "Computer";
} else {
return "Draw";
}
}
int You = random();
int Computer = random();
public static void six() {
System.out.print("---------\n| * * |\n| * * |\n| * * |\n---------");
}
public static void five() {
System.out.print("---------\n| * * |\n| * |\n| * * |\n---------");
}
public static void four() {
System.out.print("---------\n| * * |\n| |\n| * * |\n---------");
}
public static void three() {
System.out.print("---------\n| * |\n| * |\n| * |\n---------");
}
public static void two() {
System.out.print("---------\n| * |\n| |\n| * |\n---------");
}
public static void one() {
System.out.print("---------\n| |\n| * |\n| |\n---------");
}
public static int random() {
Random r = new Random();
int a = r.nextInt(6) + 1;
return a;
}
public void Dice() {
System.out.println("Your dice: ");
switch (You) {
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
}
System.out.println("\n");
System.out.println("Computer's dice: ");
switch (Computer) {
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
}
if (You > Computer) {
System.out.println("\n");
System.out.println("You won!");
} else if (Computer > You) {
System.out.println("\n");
System.out.println("You lost!");
} else {
System.out.println("\n");
System.out.println("Draw!");
}
}
}
Új hozzászólás Aktív témák
A topicot kiemeltem. Valaki nem akar egy nyitó hsz-t írni?:))
- Melyik tápegységet vegyem?
- Milyen autót vegyek?
- Motorolaj, hajtóműolaj, hűtőfolyadék, adalékok és szűrők topikja
- Gitáros topic
- The Division 2 (PC, XO, PS4)
- Lenovo Legion és IdeaPad Y széria
- Nintendo Switch 2
- AMD Navi Radeon™ RX 9xxx sorozat
- Hálózati / IP kamera
- Eredeti játékok OFF topik
- További aktív témák...
- LG 27UL550-W - 27" IPS / 3840x2160 4K / 60Hz 5ms / HDR10 / AMD FreeSync
- BESZÁMÍTÁS! Gigabyte AB350 R5 2400G 8GB DDR4 240GB SSD 500GB HDD GTX 1060 3GB Rampage SHIVA 350W
- Xiaomi Redmi Note 14 Pro 256GB Kártyafüggetlen 1Év Garanciával
- Bomba ár! Dell Latitude E6400 - Intel P8400 I 3GB I 160GB I 14,1" I Intel VGA I Garancia!
- Prémium PC házak akár 20-40% kedvezménnyel eladók garanciával, számlával!
Állásajánlatok
Cég: Promenade Publishing House Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest