changed the file structure
This commit is contained in:
parent
cd81159162
commit
b1c3582880
391 changed files with 675 additions and 0 deletions
7
Code/Steiner/dnd dice/.vscode/settings.json
vendored
Normal file
7
Code/Steiner/dnd dice/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
18
Code/Steiner/dnd dice/README.md
Normal file
18
Code/Steiner/dnd dice/README.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
BIN
Code/Steiner/dnd dice/bin/App.class
Normal file
BIN
Code/Steiner/dnd dice/bin/App.class
Normal file
Binary file not shown.
BIN
Code/Steiner/dnd dice/src/App.class
Normal file
BIN
Code/Steiner/dnd dice/src/App.class
Normal file
Binary file not shown.
51
Code/Steiner/dnd dice/src/App.java
Normal file
51
Code/Steiner/dnd dice/src/App.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
import java.util.Arrays;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
int numberOfRolls = 1000;
|
||||
int numberOfDice = 4;
|
||||
|
||||
int[] results = new int[numberOfRolls];
|
||||
|
||||
// Simulate rolling 4d6 and dropping the lowest value for 1000 times
|
||||
for (int i = 0; i < numberOfRolls; i++) {
|
||||
results[i] = rollAndDropLowest(numberOfDice);
|
||||
}
|
||||
|
||||
// Sort the results for calculating median
|
||||
Arrays.sort(results);
|
||||
|
||||
// Calculate and print lowest, highest, average, and median values
|
||||
int lowest = results[0];
|
||||
int highest = results[numberOfRolls - 1];
|
||||
double average = Arrays.stream(results).average().orElse(0);
|
||||
|
||||
int median;
|
||||
if (numberOfRolls % 2 == 0) {
|
||||
median = (results[numberOfRolls / 2 - 1] + results[numberOfRolls / 2]) / 2;
|
||||
} else {
|
||||
median = results[numberOfRolls / 2];
|
||||
}
|
||||
|
||||
System.out.println("Lowest: " + lowest);
|
||||
System.out.println("Highest: " + highest);
|
||||
System.out.println("Average: " + average);
|
||||
System.out.println("Median: " + median);
|
||||
}
|
||||
|
||||
// Simulate rolling n dice and dropping the lowest value
|
||||
private static int rollAndDropLowest(int n) {
|
||||
int[] rolls = new int[n];
|
||||
|
||||
// Roll the dice
|
||||
for (int i = 0; i < n; i++) {
|
||||
rolls[i] = (int) (Math.random() * 6) + 1;
|
||||
}
|
||||
|
||||
// Sort the rolls and drop the lowest value
|
||||
Arrays.sort(rolls);
|
||||
int sum = rolls[1] + rolls[2] + rolls[3];
|
||||
|
||||
return sum;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue