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,4 +1,4 @@
package lab0;
package dev.sowinski.comp1510.lab0;
/**
* HelloWorld prints hello world.
@@ -1,4 +1,4 @@
package lab1;
package dev.sowinski.comp1510.lab1;
/**
* Birds demos concatonation.
@@ -1,4 +1,4 @@
package lab1;
package dev.sowinski.comp1510.lab1;
/**
* 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.
@@ -1,4 +1,4 @@
package lab1;
package dev.sowinski.comp1510.lab1;
/**
* Plus demonstrates the different behaviours of the + operator.
@@ -1,4 +1,4 @@
package lab1;
package dev.sowinski.comp1510.lab1;
/**
* Poem prints a poem.
@@ -1,4 +1,4 @@
package lab1;
package dev.sowinski.comp1510.lab1;
/**
* Problems contains problems to fix.
@@ -1,4 +1,4 @@
package lab1;
package dev.sowinski.comp1510.lab1;
/**
* Simple talk about valid variable identifiers.
@@ -1,4 +1,4 @@
package lab2;
package dev.sowinski.comp1510.lab2;
import java.util.Scanner;
@@ -1,4 +1,4 @@
package lab2;
package dev.sowinski.comp1510.lab2;
import java.util.Scanner;
@@ -1,4 +1,4 @@
package lab2;
package dev.sowinski.comp1510.lab2;
import java.util.Scanner;
@@ -1,4 +1,4 @@
package lab2;
package dev.sowinski.comp1510.lab2;
/*
* int x; -> initialized empty variable
@@ -1,4 +1,4 @@
package lab2;
package dev.sowinski.comp1510.lab2;
/**
* Student holds information of a student.
@@ -1,4 +1,4 @@
package lab2;
package dev.sowinski.comp1510.lab2;
/**
* Students prints a table of student info.
@@ -1,4 +1,4 @@
package lab3;
package dev.sowinski.comp1510.lab3;
/**
* CardGame give a random card.
@@ -1,4 +1,4 @@
package lab3;
package dev.sowinski.comp1510.lab3;
/**
* Dice simulate dice rolling.
@@ -1,4 +1,4 @@
package lab3;
package dev.sowinski.comp1510.lab3;
import java.util.Scanner;
@@ -1,4 +1,4 @@
package lab3;
package dev.sowinski.comp1510.lab3;
import java.util.Scanner;
@@ -29,7 +29,7 @@ public class FunWithStrings {
System.out.printf("Starts with \"The\": %b\n",
book.toLowerCase().startsWith("the "));
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
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 {
}