Ú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?:))
- ÚJ, KOMPAKT GAMER PC - RYZEN 5 5600, RX 9060 XT 16GB, 32GB RAM, 1TB NVME SSD
- Apple iPhone 14 Pro Max 256GB,Újszerű,Dobozaval,12 hónap garanciával
- Apple MacBook Air M3 15 256GB,Újszerű,Dobozaval,24 hónap garanciával
- SAPPHIRE RX 6950 XT 16GB GDDR6 NITRO+ GAMING OC - Gari 2026.05.02. -ig - Eladó!
- Magyar Core I9 Dell Precision 7560 (Core I9 11950h 32Gb 512Gb 4Gb Nvidia) laptopom eladó!
- AKCIÓ! Microsoft XBOX Series S 512GB játékkonzol garanciával hibátlan működéssel
- Gainward RTX 5060 Ti Python III 16GB GDDR7 128bit (NE7506T019T1-GB2061T) Videokártya
- HP ProDesk 400, 600 G2,G3 Mini és 600 G2 MT , félkonfig, bővítési opció, mini PC/NAS/HTPC alap
- iPhone 15 128GB 100% (1év Garancia)- ÚJ EREDETI AKKUMULÁTOR - AKCIÓ
- AKCIÓ! Microsoft XBOX Series X 1TB SSD fekete játékkonzol extra fejhallgatóval garanciával
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest


