Removed spaces from top-level directory names.

Spaces tend to cause annoyances in a Unix-style shell environment.
This change fixes that.
This commit is contained in:
Chris Reuter
2021-11-21 18:30:21 -05:00
parent df2e7426eb
commit d26dbf036a
1725 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import java.util.Scanner;
public class Number {
public static void main(String[] args) {
printIntro();
int points = 100; //start with 100 points for the user
Scanner scan = new Scanner(System.in);
boolean done = false;
while (!done) {
System.out.print("GUESS A NUMBER FROM 1 TO 5? ");
int g = scan.nextInt();
//Initialize 5 random numbers between 1-5
var r = randomNumber(1);
var s = randomNumber(1);
var t = randomNumber(1);
var u = randomNumber(1);
var v = randomNumber(1);
if (r == g) {
points -= 5;
} else if (s == g) {
points += 5;
} else if (t == g) {
points += points;
} else if (u == g) {
points += 1;
} else if (v == g) {
points -= points * 0.5;
} else {
continue; //Doesn't match any of our random numbers, so just ask for another guess
}
if (points > 500) {
done = true;
} else {
System.out.println("YOU HAVE " + points + " POINTS.");
}
}
System.out.println("!!!!YOU WIN!!!! WITH " + points + " POINTS.\n");
}
private static int randomNumber(int x) {
//Note: 'x' is totally ignored as was in the original basic listing
return (int) (5 * Math.random() + 1);
}
private static void printIntro() {
System.out.println(" NUMBER");
System.out.println(" CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println("\n\n\n");
System.out.println("YOU HAVE 100 POINTS. BY GUESSING NUMBERS FROM 1 TO 5, YOU");
System.out.println("CAN GAIN OR LOSE POINTS DEPENDING UPON HOW CLOSE YOU GET TO");
System.out.println("A RANDOM NUMBER SELECTED BY THE COMPUTER.");
System.out.println("\n");
System.out.println("YOU OCCASIONALLY WILL GET A JACKPOT WHICH WILL DOUBLE(!)");
System.out.println("YOUR POINT COUNT. YOU WIN WHEN YOU GET 500 POINTS.");
}
}

3
66_Number/java/README.md Normal file
View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Oracle Java](https://openjdk.java.net/)

69
66_Number/java/main.class Normal file
View File

@@ -0,0 +1,69 @@
import java.time.temporal.ValueRange;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Number {
public static int points = 0;
public static void printempty() { System.out.println(" "); }
public static void print(String toprint) { System.out.println(toprint); }
public static void main(String[] args) {
print("YOU HAVE 100 POINTS. BY GUESSING NUMBERS FROM 1 TO 5, YOU");
print("CAN GAIN OR LOSE POINTS DEPENDING UPON HOW CLOSE YOU GET TO");
print("A RANDOM NUMBER SELECTED BY THE COMPUTER.");
printempty();
print("YOU OCCASIONALLY WILL GET A JACKPOT WHICH WILL DOUBLE(!)");
print("YOUR POINT COUNT. YOU WIN WHEN YOU GET 500 POINTS.");
printempty();
try {
while (true) {
print("GUESS A NUMBER FROM 1 TO 5");
Scanner numbersc = new Scanner(System.in);
String numberstring = numbersc.nextLine();
int number = Integer.parseInt(numberstring);
if (!(number < 1| number > 5)) {
Random rand = new Random();
int randomNum = rand.nextInt((5 - 1) + 1) + 1;
if (randomNum == number) {
print("YOU HIT THE JACKPOT!!!");
points = points * 2;
} else if(ValueRange.of(randomNum, randomNum + 1).isValidIntValue(number)) {
print("+5");
points = points + 5;
} else if(ValueRange.of(randomNum - 1, randomNum + 2).isValidIntValue(number)) {
print("+1");
points = points + 1;
} else if(ValueRange.of(randomNum - 3, randomNum + 1).isValidIntValue(number)) {
print("-1");
points = points - 1;
} else {
print("-half");
points = (int) (points * 0.5);
}
print("YOU HAVE " + points + " POINTS.");
}
if (points >= 500) {
print("!!!!YOU WIN!!!! WITH " + points + " POINTS.");
return;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}