update package names + lab4

This commit is contained in:
SowinskiBraeden committed 2025-02-01 14:59:55 -08:00
1 parent 1cb6bc133e
commit 38b091c51a
30 files changed
+100528 -30

No files matched your search

+1
View File
@@ -6,5 +6,6 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
-3
View File
@@ -1,5 +1,2 @@
# Test files
src/test/*
# class files # class files
bin/* bin/*
@@ -1,4 +1,4 @@
package lab0; package dev.sowinski.comp1510.lab0;
/** /**
* HelloWorld prints hello world. * HelloWorld prints hello world.
@@ -1,4 +1,4 @@
package lab1; package dev.sowinski.comp1510.lab1;
/** /**
* Birds demos concatonation. * Birds demos concatonation.
@@ -1,4 +1,4 @@
package lab1; package dev.sowinski.comp1510.lab1;
/** /**
* This program prints out 1 to 5 in three languages. * This program prints out 1 to 5 in three languages.
@@ -1,4 +1,4 @@
package lab1; package dev.sowinski.comp1510.lab1;
/** /**
* Prints hello world message. * Prints hello world message.
@@ -1,4 +1,4 @@
package lab1; package dev.sowinski.comp1510.lab1;
/** /**
* Plus demonstrates the different behaviours of the + operator. * Plus demonstrates the different behaviours of the + operator.
@@ -1,4 +1,4 @@
package lab1; package dev.sowinski.comp1510.lab1;
/** /**
* Poem prints a poem. * Poem prints a poem.
@@ -1,4 +1,4 @@
package lab1; package dev.sowinski.comp1510.lab1;
/** /**
* Problems contains problems to fix. * Problems contains problems to fix.
@@ -1,4 +1,4 @@
package lab1; package dev.sowinski.comp1510.lab1;
/** /**
* Simple talk about valid variable identifiers. * Simple talk about valid variable identifiers.
@@ -1,4 +1,4 @@
package lab2; package dev.sowinski.comp1510.lab2;
import java.util.Scanner; import java.util.Scanner;
@@ -1,4 +1,4 @@
package lab2; package dev.sowinski.comp1510.lab2;
import java.util.Scanner; import java.util.Scanner;
@@ -1,4 +1,4 @@
package lab2; package dev.sowinski.comp1510.lab2;
import java.util.Scanner; import java.util.Scanner;
@@ -1,4 +1,4 @@
package lab2; package dev.sowinski.comp1510.lab2;
/* /*
* int x; -> initialized empty variable * int x; -> initialized empty variable
@@ -1,4 +1,4 @@
package lab2; package dev.sowinski.comp1510.lab2;
/** /**
* Student holds information of a student. * Student holds information of a student.
@@ -1,4 +1,4 @@
package lab2; package dev.sowinski.comp1510.lab2;
/** /**
* Students prints a table of student info. * Students prints a table of student info.
@@ -1,4 +1,4 @@
package lab3; package dev.sowinski.comp1510.lab3;
/** /**
* CardGame give a random card. * CardGame give a random card.
@@ -1,4 +1,4 @@
package lab3; package dev.sowinski.comp1510.lab3;
/** /**
* Dice simulate dice rolling. * Dice simulate dice rolling.
@@ -1,4 +1,4 @@
package lab3; package dev.sowinski.comp1510.lab3;
import java.util.Scanner; import java.util.Scanner;
@@ -1,4 +1,4 @@
package lab3; package dev.sowinski.comp1510.lab3;
import java.util.Scanner; import java.util.Scanner;
@@ -29,7 +29,7 @@ public class FunWithStrings {
System.out.printf("Starts with \"The\": %b\n", System.out.printf("Starts with \"The\": %b\n",
book.toLowerCase().startsWith("the ")); book.toLowerCase().startsWith("the "));
System.out.printf("Title uppercased: %s\n", book.toUpperCase()); System.out.printf("Title uppercased: %s\n", book.toUpperCase());
System.out.printf("Title: %s\n", book); System.out.printf("Title lowercased: %s\n", book.toLowerCase());
// Very clean code here -- checkstyle // Very clean code here -- checkstyle
int len = trimmedBook.length(); int len = trimmedBook.length();
@@ -0,0 +1,46 @@
package dev.sowinski.comp1510.lab4;
import java.util.Scanner;
/**
* IntegerWrapper provides wrapper
* methods for integers.
*
* @author Braeden Sowinski
* @version 1.0.0
*/
public class IntegerWrapper {
/**
* main program entry.
* @param args cli input unused
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer: ");
int x = scan.nextInt();
System.out.println("Binary: " + Integer.toBinaryString(x));
System.out.println("Octal: " + Integer.toOctalString(x));
System.out.println("Hex: " + Integer.toHexString(x));
System.out.println();
System.out.println("Max Value: " + Integer.MAX_VALUE);
System.out.println("Min Value: " + Integer.MIN_VALUE);
System.out.println();
System.out.print("Enter an integer: ");
String y = scan.next();
System.out.print("Enter an integer: ");
String z = scan.next();
scan.close();
int a = Integer.parseInt(y);
int b = Integer.parseInt(z);
System.out.println("Sum of (" + a + " + " + b + ") = " + (a + b));
}
}
@@ -0,0 +1,66 @@
package dev.sowinski.comp1510.lab4;
/**
* Represents one die (singular of dice) with faces showing values between 1 and
* 6.
*
* Rename class from Die to MultiDie.
*
* @author Lewis & Loftus 9e
* @author BCIT
* @author Braeden Sowinski
* @version 2025
*/
public class MultiDie {
/** Maximum face value. */
public final int max;
/** Current value showing on the die. */
private int faceValue;
/**
* Constructor sets the initial face value to 1.
* @param numSides int Maximum face value
*/
public MultiDie(int numSides) {
max = numSides;
faceValue = roll();
}
/**
* Rolls this Die and returns the result.
* @return faceValue as an int
*/
public int roll() {
faceValue = (int) (Math.random() * max) + 1;
return faceValue;
}
/**
* Sets the face value of this Die to the specified value.
* @param value an int
*/
public void setFaceValue(int value) {
faceValue = value;
}
/**
* Returns the face value of this Die as an int.
* @return faceValue as an int
*/
public int getFaceValue() {
return faceValue;
}
/**
* Returns a String representation of this Die.
* @return toString description
*/
public String toString() {
String result = Integer.toString(faceValue);
return result;
}
}
+59
View File
@@ -0,0 +1,59 @@
package dev.sowinski.comp1510.lab4;
/**
* Name contains name information.
*
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Name {
/** first name. */
private String first;
/** middle name. */
private String middle;
/** last name. */
private String last;
/**
* Name constructor.
* @param firstName stores given first name
* @param middleName stores given middle name
* @param lastName stores given last name
*/
public Name(String firstName, String middleName, String lastName) {
first = firstName;
middle = middleName;
last = lastName;
}
/** getFirst.
* @return first name as String
*/
public String getFirst() {
return first;
}
/** getMiddle.
* @return middle name as String
*/
public String getMiddle() {
return middle;
}
/** getMiddle.
* @return middle name as String
*/
public String getLast() {
return last;
}
/** toString compiles all names.
* @return full name as String.
*/
public String toString() {
return first + " " + middle + " " + last;
}
}
+19
View File
@@ -0,0 +1,19 @@
package dev.sowinski.comp1510.lab4;
/**
* Names test Name class.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Names {
/**
* main program entry.
* @param args cli input unused
*/
public static void main(String[] args) {
Name myName = new Name("Braeden", "M", "Sowinski");
System.out.println(myName.toString());
}
}
@@ -0,0 +1,64 @@
package dev.sowinski.comp1510.lab4;
/**
* RollingMultiDice test the modified MultiDie class.
*
* @author Braeden Sowinski
* @version 1.0.0
*/
public class RollingMultiDice {
/**
* main program entry.
* @param args cli input unused
*/
public static void main(String[] args) {
final int numSides = 12;
MultiDie die = new MultiDie(numSides);
System.out.println(die.max);
/*
* 1. Do you need getters and setters for max? Should you have them?
*
* You don't need a getter for max, or a setter
* for max as it is a constant value that is set
* in the constructor
*
*
* 2. Can you have getters and setters for max?
*
* You can have a getter, though its not needed for
* max. You can't have a setter, it is a constant
* value.
*
*
* 3. Why do you think it makes sense (or not) to have max be final?
*
* It makes sense to have max as a final (constant)
* as we do not intend for a die to change its number
* of faces. It has a single number of faces that does
* not change.
*
*
* 4. What does maxs being final say about the abstraction of a
* MultiDie object?
*
*
*
* 5. Is max an instance variable.
*
* Yes max is a instance variable as it is defined in the
* class level and does not have the static modifier. Each
* object instance of this class will have unique max values.
*
* 6. Should you use a record for your Die? Why or why not?
*
* No, using a record means max will be defined as a final
* instance variable and all MultiDie objects will have the
* same max value.
*
*/
}
}
+120
View File
@@ -0,0 +1,120 @@
package dev.sowinski.comp1510.lab4;
/*
* To be updated, cannot find StudentTest.java
* file on D2L.
*/
/**
* Student contains student info.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Student {
/** firstName student first name as String. */
private String firstName;
/** lastName student last name as String. */
private String lastName;
/** birthYear student year of birth as int. */
private int birthYear;
/** gpa student GPA as int. */
private float gpa;
/**
* Student constructor.
* @param first student firstname
* @param last student lastname
* @param yearOfBirth student birth year
* @param studentGPA student gpa
*/
public Student(
String first,
String last,
int yearOfBirth,
float studentGPA
) {
firstName = first;
lastName = last;
birthYear = yearOfBirth;
gpa = studentGPA;
}
/**
* getFirstName returns student first name.
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* setFirstName updates student first name.
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* getLastName returns student last name.
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* setLastName updates student last name.
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* getBirthYear returns student year of birth.
* @return the birthYear
*/
public int getBirthYear() {
return birthYear;
}
/**
* setBirthYear updates student year of birth.
* @param birthYear the birthYear to set
*/
public void setBirthYear(int birthYear) {
this.birthYear = birthYear;
}
/**
* getGPA returns student GPA.
* @return the gpa
*/
public float getGPA() {
return gpa;
}
/**
* setGPA update student GPA.
* @param newGPA the gpa to set
*/
public void setGPA(float newGPA) {
this.gpa = newGPA;
}
/**
* toString concatonates student information.
* @return student info as a String
*/
public String toString() {
return firstName + " "
+ lastName + " ("
+ birthYear + ") "
+ gpa + " GPA";
}
}
-8
View File
@@ -1,8 +0,0 @@
/**
*
*/
/**
*
*/
module lab0 {
}
@@ -0,0 +1,96 @@
package dev.sowinski.comp1510.strings;
import java.io.IOException;
import java.io.PrintWriter;
/**
* StringReverse test different methods to reverse strings.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class StringReverse {
/**
* linearReverse reverse strings by looping over each element.
* @param s string to reverse
* @return reversed string as String
*/
public static String linearReverse(String s) {
String n = "";
for (int i = s.length() - 1; i >= 0; i--) {
n += s.charAt(i);
}
return n;
}
/**
* halfLinearReverse reverses strings by only looping
* over half of the string.
* @param s string to reverse
* @return reversed string
*/
public static String halfLinearReverse(String s) {
char r;
char[] n = s.toCharArray();
for (int i = 0; i < n.length / 2; i++) {
r = n[n.length - 1 - i];
n[n.length - 1 - i] = n[i];
n[i] = r;
}
return new String(n);
}
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
char[] charset = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1',
'2', '3', '4', '5', '6', '7', '8', '9', '0'
};
String test = new String(charset);
long start;
long end;
final int upperBound = 100000;
final int micro = 1000;
try {
PrintWriter myWriter = new PrintWriter("output.csv", "UTF-8");
for (int i = 0; i < upperBound; i++) {
start = System.nanoTime();
String r1 = new StringBuffer(test).reverse().toString();
r1.length();
end = System.nanoTime();
int duration1 = (int) ((end - start) / micro);
start = System.nanoTime();
r1 = halfLinearReverse(test);
end = System.nanoTime();
int duration3 = (int) ((end - start) / micro);
int len = test.length() + 1;
System.out.println(len - 1);
int rand = (int) (Math.random() * charset.length);
test += charset[rand];
String data = len + ","
+ duration1 + ","
+ duration3;
myWriter.println(data);
}
myWriter.close();
System.out.println("Done");
} catch (IOException e) {
System.out.println("An error occured!");
e.printStackTrace();
}
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,38 @@
import matplotlib.pyplot as plt
import csv
import numpy
x = []
y1 = []
y2 = []
with open('output.csv', newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',')
# i = 0
for row in spamreader:
# i += 1
x.append(int(row[0]))
y1.append(int(row[1]))
y2.append(int(row[2]))
# if i == 100: break
x = x[0::250]
y1 = y1[0::250]
y2 = y2[0::250]
plt.xlabel("String Length")
plt.ylabel("Microseconds (0.000001 seconds)")
plt.plot(x, y1, label="Java String Reverse")
plt.plot(x, y2, label="Half Linear Reverse")
z1 = numpy.polyfit(x, y1, 1)
p1 = numpy.poly1d(z1)
plt.plot(x, p1(x), "r--", label="Java String Reverse Trend")
z1 = numpy.polyfit(x, y2, 1)
p1 = numpy.poly1d(z1)
plt.plot(x, p1(x), "g--", label="Half Linear Reverse Trend")
plt.legend()
plt.show()