Ú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?:))
- Gitáros topic
- Samsung Galaxy Z Fold7 - ezt vártuk, de…
- Formula-1
- Pánik a memóriapiacon
- Google Pixel 9 Pro XL - hét szűk esztendő
- Hardcore café
- Xbox Series X|S
- NVIDIA GeForce RTX 5070 / 5070 Ti (GB205 / 203)
- Az idei év nagy kérdése: bele lehet férni 8 GB VRAM-ba?
- Samsung Galaxy A54 - türelemjáték
- További aktív témák...
- Google Pixel Kijelző csere BP XIII.Ker Google Pixel Akku csere +36705709017
- X13 Yoga Gen3 2-in-1 27% 13.3" QHD+ IPS érintő i5-1245U 32GB 512GB NVMe IR kam aktív toll gar
- Gamer és munka PC - Intel Core i5-12400F - RTX 2070Super - 16GB DDR4
- Samsung Galaxy tőltőcsatlakozó csere akár 1 órán belűl +36705709017
- Wiim Amp Ultra Ezüst For SALE
- ÁRGARANCIA!Épített KomPhone Ryzen 7 9800X3D 32/64GB RAM RTX 5070 12GB GAMER PC termékbeszámítással
- Apple iPhone 16 Pro Max 256GB, Kártyafüggetlen, 1 Év Garanciával
- BESZÁMÍTÁS! Asus TUF A16 2024 FA607NUG Gamer notebook - R7 7445HS 16GB DDR5 1TB SSD RTX 4050 6GB
- RAPOO 7100P 1000DPI optikai rádiós 5GHz egér
- VeryBig! Akciós! Dell Precision 7760 i7-11850H 32GB 512GB SSD RTX A5000 16GB 17" FHD 1 év garancia
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest

