Compare commits
No commits in common. "master" and "1.0" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -152,4 +152,3 @@ $RECYCLE.BIN/
|
|||||||
# Windows shortcuts
|
# Windows shortcuts
|
||||||
*.lnk
|
*.lnk
|
||||||
|
|
||||||
data/
|
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module version="4">
|
<module version="4">
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager">
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$/../../src/main">
|
<content url="file://$MODULE_DIR$/../../src/main">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="temurin-18" jdkType="JavaSDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.google.code.gson:gson:2.10.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.miglayout:miglayout:3.7.4" level="project" />
|
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,9 +1,8 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'com.github.johnrengelman.shadow' version '5.2.0'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'tech.nevets'
|
group 'org.example'
|
||||||
version '1.0'
|
version '1.0'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@ -11,14 +10,12 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.google.code.gson:gson:2.10.1'
|
|
||||||
implementation 'com.miglayout:miglayout:3.7.4'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes(
|
attributes(
|
||||||
'Main-Class': 'tech.nevets.STEmployeeHours'
|
'Main-Class': 'org.example.Main'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1 +0,0 @@
|
|||||||
January is the first month and december is the last. Violet is a purple color as are lilac and plum.
|
|
@ -1,14 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
import tech.nevets.util.DataUtils;
|
|
||||||
import tech.nevets.util.Employee;
|
|
||||||
|
|
||||||
public class Debug {
|
|
||||||
static Employee e = new Employee(100, "Steven", "Tracey");
|
|
||||||
static Employee[] arr = new Employee[]{e};
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
new DataUtils<>(Employee.class).saveToDataArray(arr, "EmployeeData", Employee[].class);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
import tech.nevets.util.Die;
|
|
||||||
|
|
||||||
public class STDieArguments {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
final int SIX_SIDES = 6;
|
|
||||||
final int TWENTY_SIDES = 20;
|
|
||||||
|
|
||||||
Die sixDie = new Die(SIX_SIDES);
|
|
||||||
Die twentyDie = new Die(TWENTY_SIDES);
|
|
||||||
|
|
||||||
rollDie(sixDie);
|
|
||||||
rollDie(twentyDie);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void rollDie(Die d) {
|
|
||||||
System.out.println("Rolling a " + d.getSides() + " sided die.");
|
|
||||||
System.out.println("The die's value: " + d.roll());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,214 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
|
||||||
import tech.nevets.util.CastUtils;
|
|
||||||
import tech.nevets.util.DataUtils;
|
|
||||||
import tech.nevets.util.Employee;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
import java.awt.event.WindowAdapter;
|
|
||||||
import java.awt.event.WindowEvent;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
public class STEmployeeHours extends JFrame {
|
|
||||||
|
|
||||||
private JPanel contentPane;
|
|
||||||
private static final ArrayList<Employee> employeeList = new ArrayList<>();
|
|
||||||
private static final DataUtils<Employee> EMPLOYEE_DATA_UTILS = new DataUtils<>(Employee.class);
|
|
||||||
private static final CastUtils<Employee> EMPLOYEE_CAST_UTILS = new CastUtils<>(Employee.class);
|
|
||||||
|
|
||||||
JLabel idLabel;
|
|
||||||
JTextField idField;
|
|
||||||
JButton submitEmpId;
|
|
||||||
JLabel empFirstName;
|
|
||||||
JLabel empLastName;
|
|
||||||
JLabel empHours;
|
|
||||||
|
|
||||||
JLabel addHoursLabel;
|
|
||||||
JTextField addHoursField;
|
|
||||||
JButton addHoursButton;
|
|
||||||
|
|
||||||
public STEmployeeHours() {
|
|
||||||
contentPane = new JPanel();
|
|
||||||
employeeList.clear();
|
|
||||||
employeeList.addAll(List.of(EMPLOYEE_CAST_UTILS.castArray(EMPLOYEE_DATA_UTILS.getArrayFromData("EmployeeData"))));
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
addWindowListener(new WindowAdapter() {
|
|
||||||
@Override
|
|
||||||
public void windowClosing(WindowEvent e) {
|
|
||||||
EMPLOYEE_DATA_UTILS.saveToDataArray(EMPLOYEE_CAST_UTILS.castArray(employeeList.toArray()), "EmployeeData", Employee[].class);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
setContentPane(contentPane);
|
|
||||||
contentPane.setBorder(new EmptyBorder(1, 1, 1, 1));
|
|
||||||
MigLayout layout = new MigLayout(
|
|
||||||
"",
|
|
||||||
"[][fill][]",
|
|
||||||
"[][][][][][]"
|
|
||||||
);
|
|
||||||
contentPane.setLayout(layout);
|
|
||||||
|
|
||||||
idLabel = new JLabel("Employee Id:");
|
|
||||||
contentPane.add(idLabel, "cell 0 0");
|
|
||||||
idField = new JTextField();
|
|
||||||
contentPane.add(idField, "cell 1 0,w 150");
|
|
||||||
|
|
||||||
AtomicInteger empIdCache = new AtomicInteger();
|
|
||||||
submitEmpId = new JButton("Submit");
|
|
||||||
submitEmpId.addActionListener(al -> {
|
|
||||||
empIdCache.set(Integer.parseInt(idField.getText()));
|
|
||||||
boolean isFound = false;
|
|
||||||
for (Employee e : employeeList) {
|
|
||||||
if (idField.getText().equals(String.valueOf(e.getEmployeeId()))) {
|
|
||||||
isFound = true;
|
|
||||||
idLabel.setText("Employee Id:");
|
|
||||||
updateUI(e);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isFound) {
|
|
||||||
idLabel.setText("User Not Found");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
contentPane.add(submitEmpId, "cell 2 0");
|
|
||||||
|
|
||||||
empFirstName = new JLabel("First Name: ");
|
|
||||||
contentPane.add(empFirstName, "cell 1 1");
|
|
||||||
empLastName = new JLabel("Last Name: ");
|
|
||||||
contentPane.add(empLastName, "cell 1 2");
|
|
||||||
empHours = new JLabel("Total Hours: ");
|
|
||||||
contentPane.add(empHours, "cell 1 3");
|
|
||||||
|
|
||||||
addHoursLabel = new JLabel("Hours To Add:");
|
|
||||||
contentPane.add(addHoursLabel, "cell 0 4");
|
|
||||||
addHoursField = new JTextField();
|
|
||||||
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("");
|
|
||||||
});
|
|
||||||
contentPane.add(addHoursButton, "cell 2 4,grow");
|
|
||||||
|
|
||||||
JButton newUserBtn = new JButton("New User");
|
|
||||||
newUserBtn.addActionListener(al -> {
|
|
||||||
AddUserFrame newUserFrame = new AddUserFrame();
|
|
||||||
newUserFrame.setLocationRelativeTo(null);
|
|
||||||
newUserFrame.pack();
|
|
||||||
newUserFrame.setVisible(true);
|
|
||||||
});
|
|
||||||
contentPane.add(newUserBtn, "cell 1 5,grow");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateUI(Employee e) {
|
|
||||||
empFirstName.setText("First Name: " + e.getEmployeeFirstName());
|
|
||||||
empLastName.setText("Last Name: " + e.getEmployeeLastName());
|
|
||||||
empHours.setText("Total Hours: " + e.getEmployeeHours());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateUI(int empId) {
|
|
||||||
for (Employee e : employeeList) {
|
|
||||||
if (e.getEmployeeId() == empId) {
|
|
||||||
empFirstName.setText("First Name: " + e.getEmployeeFirstName());
|
|
||||||
empLastName.setText("Last Name: " + e.getEmployeeLastName());
|
|
||||||
empHours.setText("Total Hours: " + e.getEmployeeHours());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateEmpHours(int id, int hoursToAdd) {
|
|
||||||
for (Employee e : employeeList) {
|
|
||||||
if (e.getEmployeeId() == id) {
|
|
||||||
e.addHours(hoursToAdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
STEmployeeHours frame = new STEmployeeHours();
|
|
||||||
frame.setBounds(0, 0, 860, 480);
|
|
||||||
frame.setLocationRelativeTo(null);
|
|
||||||
frame.pack();
|
|
||||||
frame.setVisible(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class AddUserFrame extends JFrame {
|
|
||||||
public AddUserFrame() {
|
|
||||||
setResizable(false);
|
|
||||||
JPanel auContentPane = new JPanel();
|
|
||||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
||||||
setContentPane(auContentPane);
|
|
||||||
auContentPane.setBorder(new EmptyBorder(1, 1, 1, 1));
|
|
||||||
MigLayout layout = new MigLayout(
|
|
||||||
"",
|
|
||||||
"[][fill][]",
|
|
||||||
"[][][][][][]"
|
|
||||||
);
|
|
||||||
auContentPane.setLayout(layout);
|
|
||||||
|
|
||||||
JLabel errorLabel = new JLabel("");
|
|
||||||
auContentPane.add(errorLabel, "cell 0 5");
|
|
||||||
|
|
||||||
JLabel idLabel = new JLabel("User Id:");
|
|
||||||
auContentPane.add(idLabel, "cell 0 1");
|
|
||||||
JTextField idField = new JTextField();
|
|
||||||
auContentPane.add(idField, "cell 1 1");
|
|
||||||
JLabel firstNameLabel = new JLabel("First Name:");
|
|
||||||
auContentPane.add(firstNameLabel, "cell 0 2");
|
|
||||||
JTextField firstNameField = new JTextField();
|
|
||||||
auContentPane.add(firstNameField, "cell 1 2");
|
|
||||||
JLabel lastNameLabel = new JLabel("Last Name:");
|
|
||||||
auContentPane.add(lastNameLabel, "cell 0 3");
|
|
||||||
JTextField lastNameField = new JTextField();
|
|
||||||
auContentPane.add(lastNameField, "cell 1 3");
|
|
||||||
JButton submitButton = new JButton("Create");
|
|
||||||
submitButton.addActionListener(al -> {
|
|
||||||
boolean idExists = false;
|
|
||||||
for (Employee e : employeeList) {
|
|
||||||
if (e.getEmployeeId() == Integer.parseInt(idField.getText())) {
|
|
||||||
errorLabel.setText("User with that id already exists");
|
|
||||||
idExists = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!idExists) {
|
|
||||||
Employee e = new Employee(Integer.parseInt(idField.getText()), firstNameField.getText(), lastNameField.getText());
|
|
||||||
employeeList.add(e);
|
|
||||||
this.dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
auContentPane.add(submitButton, "cell 1 4");
|
|
||||||
JButton cancelButton = new JButton("Cancel");
|
|
||||||
cancelButton.addActionListener(al -> {
|
|
||||||
this.dispose();
|
|
||||||
});
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class STFileWriter {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String user = "stracey.intern";
|
|
||||||
String fileLocation1 = "C:\\Users\\" + user + "\\Desktop\\back-slash.txt";
|
|
||||||
String fileLocation2 = "C:/Users/" + user + "/Desktop/forward-slash.txt";
|
|
||||||
|
|
||||||
File file1 = new File(fileLocation1);
|
|
||||||
File file2 = new File(fileLocation2);
|
|
||||||
|
|
||||||
try {
|
|
||||||
file1.createNewFile();
|
|
||||||
file2.createNewFile();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
public class STMethods {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("Hello from the main method.");
|
|
||||||
|
|
||||||
displayMessage();
|
|
||||||
|
|
||||||
System.out.println("Back in the main method");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link STMethods#displayMessage()} method displays a greeting.
|
|
||||||
*/
|
|
||||||
public static void displayMessage() {
|
|
||||||
System.out.println("Hello from the displayMessage method.");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
public class STMileageD {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
JOptionPane.showMessageDialog(null, "This program will calculate mileage");
|
|
||||||
int miles = Integer.parseInt(JOptionPane.showInputDialog("Enter the miles driven"));
|
|
||||||
int gallons = Integer.parseInt(JOptionPane.showInputDialog("Enter the gallons used"));
|
|
||||||
float mpg = (float) miles / (float) gallons;
|
|
||||||
JOptionPane.showMessageDialog(null, mpg + " miles per gallon");
|
|
||||||
String mpgFormatted = String.format("%.2f miles per gallon", mpg);
|
|
||||||
JOptionPane.showMessageDialog(null, mpgFormatted);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class STMileageS {
|
|
||||||
private static Scanner sc = new Scanner(System.in);
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("This program will calculate mileage");
|
|
||||||
System.out.print("Enter the miles driven: ");
|
|
||||||
int miles = sc.nextInt();
|
|
||||||
System.out.print("Enter the gallons used: ");
|
|
||||||
int gallons = sc.nextInt();
|
|
||||||
float mpg = (float) miles / (float) gallons;
|
|
||||||
System.out.println(mpg + " miles per gallon");
|
|
||||||
System.out.printf("%.2f miles per gallon", mpg);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class STNumericTypes {
|
|
||||||
static final int NUMBER = 2;
|
|
||||||
static final int SCORE1 = 100;
|
|
||||||
static final int SCORE2 = 95;
|
|
||||||
static final int BOILING_IN_F = 212;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int fToC;
|
|
||||||
double average;
|
|
||||||
String output;
|
|
||||||
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
|
|
||||||
average = (double) (SCORE1 + SCORE2) / NUMBER;
|
|
||||||
output = SCORE1 + " and " + SCORE2 + " have an average of " + average;
|
|
||||||
System.out.println(output);
|
|
||||||
|
|
||||||
fToC = Math.round((5 / 9F) * (BOILING_IN_F - 32));
|
|
||||||
output = BOILING_IN_F + " in Fahrenheit is " + fToC + " in Celsius.";
|
|
||||||
System.out.println(output);
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
System.out.print("Enter First Name: ");
|
|
||||||
String firstName = sc.nextLine();
|
|
||||||
System.out.print("Enter Last Name: ");
|
|
||||||
String lastName = sc.nextLine();
|
|
||||||
System.out.println(firstName + " " + lastName);
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
char firstInitial = firstName.charAt(0);
|
|
||||||
System.out.println(firstInitial);
|
|
||||||
String nameUpper = firstName.toUpperCase();
|
|
||||||
System.out.println(nameUpper);
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
System.out.println("Enter Sphere Diameter: ");
|
|
||||||
int sphereDiameter = sc.nextInt();
|
|
||||||
float sphereRadius = sphereDiameter / 2.0F;
|
|
||||||
float sphereVolume = (float) ((4 / 3F) * Math.PI * (sphereRadius * sphereRadius * sphereRadius));
|
|
||||||
System.out.println(sphereVolume);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
// This program will demonstrate the function of numeric operators
|
|
||||||
|
|
||||||
// Class declarator
|
|
||||||
// Main method head
|
|
||||||
|
|
||||||
Create Scanner Object
|
|
||||||
|
|
||||||
Create constant ints for NUMBER = 2, SCORE1 = 100, SCORE2 = 95, and BOILING_IN_F = 212
|
|
||||||
Create int named fToC
|
|
||||||
Create double named average
|
|
||||||
Create String named output
|
|
||||||
|
|
||||||
Set average to SCORE1 plus SCORE2, all divided by NUMBER
|
|
||||||
Set output to SCORE1 appending " and " appending average appending " have an average of " appending average
|
|
||||||
Print output to the console
|
|
||||||
|
|
||||||
// This converts Fahrenheit to Celsius
|
|
||||||
Set fToC to 5 divided by 9 all times (BOILING_IN_F minus 32)
|
|
||||||
Set output to BOILING_IN_F appending " in Fahrenheit is " appending fToC appending " in Celsius."
|
|
||||||
Print output to the console
|
|
||||||
Print a newline to the console
|
|
||||||
|
|
||||||
// Reads user's first and last name, then appends them
|
|
||||||
Print "Enter First Name: " to console
|
|
||||||
Use previously created scanner object to read the String, setting it to variable firstName
|
|
||||||
Print "Enter Last Name: " to console
|
|
||||||
Use scanner object to read the String, setting it to variable lastName
|
|
||||||
Print firstName appending lastName to the console
|
|
||||||
Print newline to the console
|
|
||||||
|
|
||||||
Use the String method charAt passing in 0 to get the first char in the first name, setting that to a new char variable named firstInitial
|
|
||||||
Print firstInitial to the console
|
|
||||||
Use the String method toUpperCase, setting that to a new String variable named nameUpper
|
|
||||||
Print nameUpper to the console
|
|
||||||
Print newline to the console
|
|
||||||
|
|
||||||
Print "Enter Sphere Diameter: " to console
|
|
||||||
Use scanner object to get the entered int, setting it to a new variable named sphereDiameter
|
|
||||||
Create new float named sphereRadius, setting it to shpereDiameter divided by 2.0F
|
|
||||||
Create a new float named sphereVolume, setting it to (4 / 3F) * Math.PI * (sphereRadius * sphereRadius * sphereRadius)
|
|
||||||
Print sphereVolume to the console
|
|
@ -1,11 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
public class STRandomizer {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Random rand = ThreadLocalRandom.current();
|
|
||||||
rand.nextInt();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
public class STValueReturn {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int total;
|
|
||||||
int value1 = 20;
|
|
||||||
int value2 = 40;
|
|
||||||
|
|
||||||
total = sum(value1, value2);
|
|
||||||
|
|
||||||
System.out.println("The sum of " + value1 + " and " + value2 + " is " + total);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the sum of the 2 passed parameters
|
|
||||||
* @param num1 the first number to add
|
|
||||||
* @param num2 the second number to add
|
|
||||||
* @return the sum of the 2 passed numbers
|
|
||||||
*/
|
|
||||||
public static int sum(int num1, int num2) {
|
|
||||||
int result;
|
|
||||||
result = num1 + num2;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steven Tracey
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class STWelcome {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("Welcome to Java Programming.");
|
|
||||||
System.out.print("I think this class ");
|
|
||||||
System.out.println("will be awesome!");
|
|
||||||
System.out.println("I promise not to cheat in this class");
|
|
||||||
System.out.println("If caught, I will be withdrawn with an F grade");
|
|
||||||
System.out.println("Como estas hoy"); // Lang: Spanish
|
|
||||||
System.out.println("J'espere que tu aimes ce cours"); // Lang: French
|
|
||||||
System.out.println("Byona gironata"); // Lang: Italian
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
// This program prints text to console
|
|
||||||
// Steven Tracey
|
|
||||||
|
|
||||||
//class declarator
|
|
||||||
//main method
|
|
||||||
|
|
||||||
Display "Welcome to Java Programming."
|
|
||||||
Go to next line
|
|
||||||
Display "I think this class "
|
|
||||||
Display "will be awesome!"
|
|
||||||
Go to next line
|
|
||||||
Display "I promise not to cheat in this class"
|
|
||||||
Go to next line
|
|
||||||
Display "If caught, I will be withdrawn with an F grade"
|
|
||||||
Go to next line
|
|
||||||
Display "Como estas hoy"
|
|
||||||
Go to next line
|
|
||||||
Display "J'espere que tu aimes ce cours"
|
|
||||||
Go to next line
|
|
||||||
Display "Byona gironata"
|
|
||||||
|
|
||||||
End of program
|
|
@ -1,12 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steven Tracey
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public class StevenTraceyMyFirstProgram {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("Hello, World!");
|
|
||||||
System.out.println("This is my project!");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package tech.nevets;
|
|
||||||
|
|
||||||
public class Test {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int i = 5;
|
|
||||||
System.out.println("i is 5, next int is prefixed");
|
|
||||||
System.out.println(++i);
|
|
||||||
i = 5;
|
|
||||||
System.out.println("i is 5, next int is postfixed");
|
|
||||||
System.out.println(i++);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package tech.nevets.c5t9;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package tech.nevets.util;
|
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public class CastUtils<T> {
|
|
||||||
private Class<T> clazz;
|
|
||||||
|
|
||||||
public CastUtils(Class<T> clazz) {
|
|
||||||
this.clazz = clazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T[] castArray(Object[] array) {
|
|
||||||
T[] newArray = (T[]) Array.newInstance(clazz, array.length);
|
|
||||||
for (int i = 0; i < array.length; i++) {
|
|
||||||
newArray[i] = (T) array[i];
|
|
||||||
}
|
|
||||||
return newArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T castObject(Object obj) {
|
|
||||||
return (T) obj;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
package tech.nevets.util;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class DataUtils<T> {
|
|
||||||
private Class<T> clazz;
|
|
||||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
|
|
||||||
public DataUtils(Class<T> clazz) {
|
|
||||||
this.clazz = clazz;
|
|
||||||
File dataDir = new File("./data/");
|
|
||||||
if (!dataDir.exists()) {
|
|
||||||
dataDir.mkdirs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveToDataArray(T[] array, String fileName, Class<T[]> clazzLocal) {
|
|
||||||
String json = gson.toJson(array, clazzLocal);
|
|
||||||
writeJsonToFile(json, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveToDataObject(T data, String fileName) {
|
|
||||||
String json = gson.toJson(data, clazz);
|
|
||||||
writeJsonToFile(json, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeJsonToFile(String json, String fileName) {
|
|
||||||
try {
|
|
||||||
FileWriter fw = new FileWriter("./data/" + fileName + ".json");
|
|
||||||
fw.write(json);
|
|
||||||
fw.flush();
|
|
||||||
fw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public T[] getArrayFromData(String fileName) {
|
|
||||||
File file = new File("./data/" + fileName + ".json");
|
|
||||||
JsonArray ja;
|
|
||||||
try {
|
|
||||||
if (!file.exists()) {
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
|
||||||
ja = gson.fromJson(br, JsonArray.class);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ja == null) {
|
|
||||||
ja = new JsonArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
Object[] dataArray = new Object[ja.size()];
|
|
||||||
|
|
||||||
for (int i = 0; i < ja.size(); i++) {
|
|
||||||
dataArray[i] = gson.fromJson(ja.get(i).getAsJsonObject(), clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CastUtils<>(clazz).castArray(dataArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getObjectFromData(String fileName) {
|
|
||||||
try {
|
|
||||||
BufferedReader br = new BufferedReader(new FileReader("./data/" + fileName + ".json"));
|
|
||||||
return gson.fromJson(br, clazz);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package tech.nevets.util;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
public class Die {
|
|
||||||
private final int sides;
|
|
||||||
private final Random r;
|
|
||||||
|
|
||||||
public Die(int sides) {
|
|
||||||
this.sides = sides;
|
|
||||||
r = ThreadLocalRandom.current();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int roll() {
|
|
||||||
return (r.nextInt(sides - 1) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSides() {
|
|
||||||
return sides;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
package tech.nevets.util;
|
|
||||||
|
|
||||||
public class Employee {
|
|
||||||
private final int employeeId;
|
|
||||||
private final String employeeFirstName;
|
|
||||||
private final String employeeLastName;
|
|
||||||
private int employeeHours;
|
|
||||||
|
|
||||||
public Employee(int employeeId, String employeeFirstName, String employeeLastName) {
|
|
||||||
this.employeeId = employeeId;
|
|
||||||
this.employeeFirstName = employeeFirstName;
|
|
||||||
this.employeeLastName = employeeLastName;
|
|
||||||
employeeHours = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEmployeeId() {
|
|
||||||
return employeeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmployeeFirstName() {
|
|
||||||
return employeeFirstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmployeeLastName() {
|
|
||||||
return employeeLastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEmployeeHours() {
|
|
||||||
return employeeHours;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addHours(int hours) {
|
|
||||||
employeeHours += hours;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "{ \"employeeId\":" + employeeId + ", \"employeeFirstName\":\"" + employeeFirstName + "\", \"employeeLastName\":\"" + employeeLastName + "\", \"employeeHours\":" + employeeHours + " }";
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user