Compare commits
9 commits
Author | SHA1 | Date | |
---|---|---|---|
6fa68b07b8 | |||
5fe83d7ee8 | |||
19dcae87c3 | |||
a52e81d6c8 | |||
897ef9bf4b | |||
6784d02b95 | |||
befd8c1e8b | |||
9429a39b3c | |||
6ba738d773 |
3 changed files with 14 additions and 138 deletions
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* TASK 4
|
||||
* archived at https://git.femboy.science/femsci/ppj/src/branch/task/4
|
||||
* by femsci
|
||||
*/
|
||||
|
||||
// bsprng reference to femsci/bottompass 🥺
|
||||
|
||||
public class BottomSecurePRNG {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// tight or loose? choose one...
|
||||
|
||||
System.out.println("Loosely coupled generator:\n=================");
|
||||
// loosely coupled <3
|
||||
looseCouplingUwU();
|
||||
System.out.println("=================\n");
|
||||
|
||||
System.out.println("Tightly coupled generator:\n=================");
|
||||
// tightly coupled >.<
|
||||
tightCouplingඬϖඬ();
|
||||
System.out.println("=================\n");
|
||||
|
||||
}
|
||||
|
||||
private static void tightCouplingඬϖඬ() {
|
||||
// meow~
|
||||
|
||||
for (byte __ = 0; __ < 5; ++__) {
|
||||
int colourVal = (int) (Math.random() * 4 + 1), rankVal = (int) (Math.random() * 13 + 2);
|
||||
|
||||
String colour = switch (colourVal) {
|
||||
case 1 -> "Spade";
|
||||
case 2 -> "Club";
|
||||
case 3 -> "Diamond";
|
||||
case 4 -> "Heart";
|
||||
default -> throw new IllegalArgumentException("Invalid colour value: " + rankVal);
|
||||
};
|
||||
|
||||
String rank = switch (rankVal) {
|
||||
case 2 -> "Deuce";
|
||||
case 3 -> "Trey";
|
||||
case 4 -> "Four";
|
||||
case 5 -> "Five";
|
||||
case 6 -> "Six";
|
||||
case 7 -> "Seven";
|
||||
case 8 -> "Eight";
|
||||
case 9 -> "Nine";
|
||||
case 10 -> "Ten";
|
||||
case 11 -> "Jack";
|
||||
case 12 -> "Queen";
|
||||
case 13 -> "King";
|
||||
case 14 -> "Ace";
|
||||
default -> throw new IllegalArgumentException("Invalid rank value: " + rankVal);
|
||||
};
|
||||
|
||||
System.out.printf("%s of %ss\n", rank, colour);
|
||||
}
|
||||
}
|
||||
|
||||
private static void looseCouplingUwU() {
|
||||
for (byte __ = 0; __ < 5; ++__) {
|
||||
System.out.println(Card.random().getCardString());
|
||||
}
|
||||
}
|
||||
}
|
69
Card.java
69
Card.java
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* TASK 4
|
||||
* archived at https://git.femboy.science/femsci/ppj/src/branch/task/4
|
||||
* by femsci
|
||||
*/
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Card {
|
||||
public Card(Colour colour, Rank rank) {
|
||||
this.colour = colour;
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
public static Card fromRaw(int colour, int rank) {
|
||||
return new Card(Colour.from(colour), Rank.from(rank));
|
||||
}
|
||||
|
||||
public static Card random() {
|
||||
return fromRaw((int) (Math.random() * 4 + 1), (int) (Math.random() * 13 + 2));
|
||||
}
|
||||
|
||||
private Colour colour;
|
||||
private Rank rank;
|
||||
|
||||
public String getCardString() {
|
||||
return String.format("%s of %ss", rank.getName(), colour.getName());
|
||||
}
|
||||
|
||||
protected enum Colour {
|
||||
SPADE(1), CLUB(2), DIAMOND(3), HEART(4);
|
||||
|
||||
private int raw;
|
||||
|
||||
Colour(int c) {
|
||||
raw = c;
|
||||
}
|
||||
|
||||
public static Colour from(int colour) {
|
||||
// modification-proof mapping
|
||||
return Arrays.stream(Colour.values()).filter(c -> c.raw == colour).findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return String.format("%s%s", name().charAt(0), name().substring(1).toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
protected enum Rank {
|
||||
DEUCE(2), TREY(3), FOUR(4), FIVE(5),
|
||||
SIX(6), SEVEN(7), EIGHT(8), NINE(9), TEN(10),
|
||||
JACK(11), QUEEN(12), KING(13), ACE(14);
|
||||
|
||||
private int raw;
|
||||
|
||||
Rank(int c) {
|
||||
raw = c;
|
||||
}
|
||||
|
||||
public static Rank from(int rank) {
|
||||
// modification-proof mapping
|
||||
return Arrays.stream(Rank.values()).filter(r -> r.raw == rank).findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return String.format("%s%s", name().charAt(0), name().substring(1).toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
16
README.md
16
README.md
|
@ -1,5 +1,17 @@
|
|||
# PPJ
|
||||
|
||||
This branch contains the solution for the **4th task**.
|
||||
This repository exists to archive PJATK tasks for the PPJ curriculum.
|
||||
|
||||
[Go back to main](/femsci/ppj/src/branch/nya)
|
||||
Each task can be found under its **corresponding branch**: `task/n`.
|
||||
|
||||
### Completed tasks:
|
||||
|
||||
- [Task 1](/femsci/ppj/src/branch/task/1)
|
||||
- [Task 2](/femsci/ppj/src/branch/task/2)
|
||||
- [Task 3](/femsci/ppj/src/branch/task/3)
|
||||
- [Task 4](/femsci/ppj/src/branch/task/4)
|
||||
- [Task 5](/femsci/ppj/src/branch/task/5)
|
||||
- [Task 6](/femsci/ppj/src/branch/task/6)
|
||||
- [Task 7](/femsci/ppj/src/branch/task/7)
|
||||
- [Task 8](/femsci/ppj/src/branch/task/8)
|
||||
- [Task 9](/femsci/ppj/src/branch/task/9)
|
||||
|
|
Loading…
Reference in a new issue