This commit is contained in:
Steven V. Tracey 2023-04-29 21:00:22 -04:00
parent e67cd5a385
commit 873f4e7929
4 changed files with 144 additions and 1 deletions

1
secret.txt Normal file
View File

@ -0,0 +1 @@
January is the first month and december is the last. Violet is a purple color as are lilac and plum.

View File

@ -88,6 +88,9 @@ public class STEmployeeHours extends JFrame {
contentPane.add(addHoursField, "cell 1 4");
addHoursButton = new JButton("Add");
addHoursButton.addActionListener(al -> {
if (addHoursField.getText().equals("")) {
return;
}
updateEmpHours(empIdCache.get(), Integer.parseInt(addHoursField.getText()));
updateUI(empIdCache.get());
addHoursField.setText("");
@ -137,7 +140,7 @@ public class STEmployeeHours extends JFrame {
}
private class AddUserFrame extends JFrame {
private static class AddUserFrame extends JFrame {
public AddUserFrame() {
setResizable(false);
JPanel auContentPane = new JPanel();
@ -190,4 +193,22 @@ public class STEmployeeHours extends JFrame {
auContentPane.add(cancelButton, "cell 2 4");
}
}
private static class GrossPayFrame extends JFrame {
public GrossPayFrame() {
setResizable(false);
JPanel gpContentPane = new JPanel();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setContentPane(gpContentPane);
gpContentPane.setBorder(new EmptyBorder(1, 1, 1, 1));
MigLayout layout = new MigLayout(
"",
"[][fill][]",
"[][][][][][]"
);
gpContentPane.setLayout(layout);
}
}
}

View File

@ -0,0 +1,72 @@
package tech.nevets;
/**
* This class tells you which grades you achieved 100%'s on
*/
public class STSearchArray {
private static final int[] GRADES = {94, 96, 100, 97, 94, 100, 93};
public static void main(String[] args) {
// boolean stores flag in case no 100's were found
boolean atLeastOne = false;
// loops through grades, checking if each one is equal to 100
for (int i = 0; i < GRADES.length; i++) {
// if the grade equals 100, it displays which grade it is (using the getPlace method)
// then it displays which subscript it's in
// finally it sets the atLeastOne flag to true so the sorry messages does not get displayed
if (GRADES[i] == 100) {
System.out.println("Your " + getPlace(i + 1) + " grade (subscript " + i + ") is a 100%, good job!");
atLeastOne = true;
}
}
// if the atLeastOne flag is false, the sorry message will be displayed
if (!atLeastOne) {
System.out.println("Sorry, but you did not score 100% on anything :(");
}
}
/**
* I bashed my head against my keyboard until this method worked properly...
*
* This method takes a number and determines if it gets suffixed with 'st', 'nd', 'rd', or 'th'
* @param index number you want suffixed with 'st', 'nd', 'rd', or 'th'
* @return String value of # and 'st', 'nd', 'rd', or 'th'
*/
private static String getPlace(int index) {
// Separate number into individual digits (chars)
char[] digits = String.valueOf(index).toCharArray();
// Quick 'th' suffix for non-edge cases
String nonSpecial = Integer.parseInt(String.valueOf(digits)) + "th";
// Catches stupid 11th 12th and 13th cases
// Ensures number is > 9
if (digits.length > 1) {
// Ensures the tens place is 1
if (digits[digits.length - 2] == '1') {
return nonSpecial;
}
}
// Quick ternary operation to quickly deal with single digits
// This String will have 1st, 2nd, or 3rd appended if necessary
// Otherwise the switch case will return the precalculated value
final String podiumCasesPrefix = digits.length > 1 ?
String.valueOf(digits).substring(0, digits.length - 1) :
"";
// Switch case for adding the special 'st', 'nd', and 'rd' suffixes
// Or returning the initial 'th' ending
switch (digits[digits.length - 1]) {
case '1' -> {
return podiumCasesPrefix + "1st";
}
case '2' -> {
return podiumCasesPrefix + "2nd";
}
case '3' -> {
return podiumCasesPrefix + "3rd";
}
default -> {
return nonSpecial;
}
}
}
}

View File

@ -0,0 +1,49 @@
package tech.nevets;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.StringTokenizer;
/**
* This class will extract a secret word from the string in the <a href="./secret.txt">secret.txt</a> file.
* Ensure you have created a secret.txt file, with text, in the same directory as the program.
*/
public class STSecretMessage {
/**
* Main method where everything takes place
* @param args default args variable
* @throws FileNotFoundException FileReader will error out if the <a href="./secret.txt">secret.txt</a> file does not exist.
*/
public static void main(String[] args) throws FileNotFoundException {
// The following 4 lines opens a buffered reader from a file reader
// Then it creates the string by appending all the lines into a single StringBuilder
// To achieve this, I used Java's built-in Streams API
BufferedReader reader = new BufferedReader(new FileReader("./secret.txt"));
StringBuilder sb = new StringBuilder();
reader.lines().forEach(sb::append);
String secretTextRaw = sb.toString();
// Below loops through the StringTokenizer object while counting each fifth interval
StringTokenizer tokenizer = new StringTokenizer(secretTextRaw, " ", false);
StringBuilder secret = new StringBuilder();
// Here we set the counter to 4 to start with the first word in the secret text.
int count = 4;
// I initialize the String variable with the first token
// For the boolean check I make sure there are still tokens left in the buffer, preventing an exception.
// Finally, I update the String variable with the next token.
for (String s = tokenizer.nextToken(); tokenizer.countTokens() > 0; s = tokenizer.nextToken()) {
// On the fifth interval it will append the first char of the token to the secret StringBuilder
// Then reset the counter
if (count == 4) {
secret.append(s.charAt(0));
count = 0;
// On the off intervals, it increments the counter and loops again.
} else {
count++;
}
}
// This line converts the StringBuilder to a string, then turns it to all caps and writes it to the console.
System.out.println(secret.toString().toUpperCase());
}
}