initial commit

This commit is contained in:
SowinskiBraeden committed 2025-01-24 21:24:00 -08:00
commit b2230558db
25 files changed
+918

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+5
View File
@@ -0,0 +1,5 @@
# Test files
src/test/*
# class files
bin/*
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>comp1510</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
+11
View File
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
+7
View File
@@ -0,0 +1,7 @@
# comp1510
All programming methods (comp 1510) at BCIT labs.
2025
Follows all, 100% valuable, useful, totally accurate checkstyle rules.
+17
View File
@@ -0,0 +1,17 @@
package lab0;
/**
* HelloWorld prints hello world.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class HelloWorld {
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
System.out.println("This is junk!");
}
}
+23
View File
@@ -0,0 +1,23 @@
package lab1;
/**
* Birds demos concatonation.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Birds {
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
// defining these as constants due to checkstyle :(
final int ten = 10;
final int three = 3;
System.out.println("Ten robins plus "
+ (ten + three)
+ " canaries is 23 birds."
);
}
}
+33
View File
@@ -0,0 +1,33 @@
package lab1;
/**
* This program prints out 1 to 5 in three languages.
* @author = Braeden Sowinski
* @version = 1.0.0
*/
public class Count {
// below is a javadoc comment, its different from multi line by
// starting with two stars
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
// Here is 1 to 5 in English
System.out.println("One, two, three, four, five.");
// Here is 1 to 5 in French
System.out.println("Un, deux, trois, quatre, cinq.");
// Here is 1 to 5 in Spanish
System.out.println("Uno, dos, tres, cuatro, cinco");
}
}
// removing one slash from the beginning of the comment makes it invalid
// adding slashes after the first two initial slashes is ok. they are ignored
/*
* this is a multi-line comment
*/
+38
View File
@@ -0,0 +1,38 @@
package lab1;
/**
* Prints hello world message.
* @author Braeden Sowinski
* @version 1.0.0
* */
public class Hello {
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
/*
* After changing the classname to "helo", the error is:
* Error: Could not find or load main class lab1.Hello in module lab0
*
* Changing the text inside of the println function produces no errors and
* simply outputs "Helo World!" as intended.
*
* Removing the final quotation produces the error:
* String literal is not properly closed by a double-quote
*
* Removing the first quotation produces the error:
* Syntax error on token(s), misplaced construct(s)
* Syntax error on token "!", ; expected
* String literal is not properly closed by a double-quote
*
* Forgetting a semi-colon at the end of a line of code will produce a
* syntax error:
* "Syntax error, insert ";" to complete BlockStatements"
*
*/
+28
View File
@@ -0,0 +1,28 @@
package lab1;
/**
* Plus demonstrates the different behaviours of the + operator.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Plus {
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
System.out.println("This is a long string that is the"
+ " concatenation of two shorter strings.");
final int years = 70;
System.out.println("The first computer was invented about "
+ years + " years ago");
final int num1 = 8;
final int num2 = 5;
System.out.println("8 plus 5 is " + num1 + num2);
System.out.println("8 plus 5 is " + (num1 + num2));
System.out.println(num1 + num2 + " equals 8 plus 5.");
}
}
+22
View File
@@ -0,0 +1,22 @@
package lab1;
/**
* Poem prints a poem.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Poem {
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
System.out.println("Roses are red");
System.out.println("Violets are blue");
System.out.println("Sugar is sweet");
System.out.println("But I have commitment issues");
System.out.println("So I'd rather just be friends");
System.out.println("At this point in our relationship.");
}
}
+23
View File
@@ -0,0 +1,23 @@
package lab1;
/**
* Problems contains problems to fix.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Problems {
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
System.out.println("This program used to have lots ofproblems,");
System.out.println("but if it prints this, you fixed them all.");
System.out.println(" *** Hurray! ***");
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
}
// All problems have been fixed
+27
View File
@@ -0,0 +1,27 @@
package lab1;
/**
* Simple talk about valid variable identifiers.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Simple {
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
System.out.print("I love Java!\n");
}
}
/*
* simple - invalid, cannot match class name
* SimpleProgram - valid
* 1_Simple - invalid, cannot start with a number
* _simple_ - valid
* *Simple* - invalid, contains invalid characters (*)
* $123_45 - valid
* Simple! - invalid, contains an invalid character (!)
*/
+46
View File
@@ -0,0 +1,46 @@
package lab2;
import java.util.Scanner;
/**
* BaseConvert converts any base 10 number to any base.
*
* @author Braeden Sowinski
* @version 1.1.0
*/
public class BaseConvert {
/** main program entry.
* @param args unused
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Convert base 10 to base (2-9): ");
int base = scan.nextInt();
final int baseMin = 2;
final int baseMax = 9;
if (base < baseMin || base > baseMax) {
System.out.printf("Base %d is not valid", base);
scan.close();
return;
}
System.out.printf("Convert 'n' to base %d: ", base);
long n = scan.nextLong();
scan.close();
String newBase = "";
while (n != 0) {
newBase += n % base;
n /= base;
}
newBase = new StringBuffer(newBase).reverse().toString();
System.out.printf("%d in (base 10) is equal to %s (base %d).",
n,
newBase,
base
);
}
}
+54
View File
@@ -0,0 +1,54 @@
package lab2;
import java.util.Scanner;
/**
* Circle does something.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Circle {
/**
* main, entry point of the program.
* @param args unused
*/
public static void main(String[] args) {
final double pi = 3.141592654;
double radius;
Scanner scan = new Scanner(System.in);
System.out.print("Please enter a radius: ");
radius = scan.nextDouble();
System.out.print("\n");
scan.close();
double circumference = 2 * pi * radius;
double area = pi * radius * radius;
double doubleRadius = 2 * radius;
double doubleCircumference = 2 * pi * doubleRadius;
double doubleArea = 2 * doubleRadius * doubleRadius;
double diffCircumference = doubleCircumference / circumference;
double diffArea = doubleArea / area;
System.out.println("Circle of radius " + radius + ":");
System.out.println("Circumference: " + circumference);
System.out.println("Area: " + area);
System.out.println();
System.out.println("Circle of radius "
+ doubleRadius
+ " (2 * " + radius + "):");
System.out.println("Circumference: " + doubleCircumference);
System.out.println("Area: " + doubleArea);
System.out.println();
System.out.println("The area of the circle with double the radius is "
+ diffArea + " times larger");
System.out.println("The circumference of the double circle is "
+ diffCircumference + " time larger");
}
}
+49
View File
@@ -0,0 +1,49 @@
package lab2;
import java.util.Scanner;
/**
* Paint.
*
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Paint {
/** main program entry.
* @param args unused
*/
public static void main(String[] args) {
// square feet covered per can of paint
final int coverage = 400;
Scanner scan = new Scanner(System.in);
double width;
double length;
double height;
double layers;
System.out.print("Please enter room width (ft.): ");
width = scan.nextDouble();
System.out.print("Please enter room length (ft.): ");
length = scan.nextDouble();
System.out.print("Please enter room height (ft.): ");
height = scan.nextDouble();
System.out.print("Please enter number of layers: ");
layers = scan.nextDouble();
scan.close();
double surfaceArea = (width * height * 2)
+ (length * height * 2) + (width * length);
double coverageNeeded = surfaceArea * layers;
int cansOfPaint = (int) Math.ceil(coverageNeeded / coverage);
System.out.println("You need " + cansOfPaint + " cans of paint.");
}
}
+60
View File
@@ -0,0 +1,60 @@
package lab2;
/*
* int x; -> initialized empty variable
* int x = 3; -> initialized variable and assigned value 3;
* x = 3; -> assigned value 3 to variable x
*/
/**
* Prelab answers to questions.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Prelab {
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
final int a = 3;
final int b = 9;
final int c = 7;
final double w = 12.9;
final double y = 3.2;
// b * c first then add a
System.out.println(a + b * c);
// left to right
System.out.println(a - b - c);
// left to right
System.out.println(a / b);
// left to right
System.out.println(b / a);
// b / c then subtract from a
System.out.println(a - b / c);
// left to right
System.out.println(w / y);
// left to right
System.out.println(y / w);
// w / b then subtract from a
System.out.println(a + w / b);
// left to right
System.out.println(a % b / y);
// left to right
System.out.println(b % a);
// left to right
System.out.println(w % y);
}
}
+78
View File
@@ -0,0 +1,78 @@
package lab2;
/**
* Student holds information of a student.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Student {
/**
* Student holds student info.
* @param name student name
*/
private String name;
/**
* lab points.
* @param lab student points for lab
*/
private int lab;
/**
* bonus points.
* @param bonus student points for bonus
*/
private int bonus;
/**
* total points.
* @param total is lab + bonus
*/
private int total;
/**
* Student constructor.
* @param newName name of student
* @param newLab lab points of student
* @param newBonus bonus points of student
*/
public Student(String newName, int newLab, int newBonus) {
name = newName;
lab = newLab;
bonus = newBonus;
total = lab + bonus;
}
/**
* getName returns name.
* @return name string
*/
public String getName() {
return name;
}
/**
* getLab returns lab.
* @return lab int
*/
public int getLab() {
return lab;
}
/**
* getBonus returns bonus.
* @return bonus int
*/
public int getBonus() {
return bonus;
}
/**
* getTotal returns total.
* @return total int
*/
public int getTotal() {
return total;
}
}
+122
View File
@@ -0,0 +1,122 @@
package lab2;
/**
* Students prints a table of student info.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Students {
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
final int maxScore = 101;
Student[] students = {
new Student("Joe",
(int) (Math.random() * maxScore),
(int) (Math.random() * maxScore)),
new Student("William",
(int) (Math.random() * maxScore),
(int) (Math.random() * maxScore)),
new Student("Mary Sue",
(int) (Math.random() * maxScore),
(int) (Math.random() * maxScore)),
new Student("Peng",
(int) (Math.random() * maxScore),
(int) (Math.random() * maxScore)),
new Student("Kwon",
(int) (Math.random() * maxScore),
(int) (Math.random() * maxScore)),
};
String nameBuff = " ";
String labBuff = " ";
String bonusBuff = " ";
// Yes, longer than 80 characters is too long, lets just split
// our for loops in half to please the checkstyle gods.
// And dont think we can put students[i].getName().length()
// into a variable, as well as lab and bonus.
// because then the main functions has too many statements.
// Thank you checkstyle
for (int i = 0; i < students.length; i++) {
if (students[i].getName().length() > nameBuff.length()) {
for (int j = 0; j < students[i].getName().length()
- "name ".length(); j++) {
nameBuff += " ";
}
}
if (("" + students[i].getLab()).length() > labBuff.length()) {
for (int j = 0; j < ("" + students[i].getLab()).length()
- "lab ".length(); j++) {
labBuff += " ";
}
}
if (("" + students[i].getBonus()).length() > bonusBuff.length()) {
for (int j = 0; j < ("" + students[i].getBonus()).length()
- "bonus ".length(); j++) {
bonusBuff += " ";
}
}
}
// Print out neat header
System.out.println("///////////////////"
+ "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\");
System.out.println(" == Student Points ==");
System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
+ "///////////////////");
// Print column names with proper padding
System.out.printf("Name%slab%sBonus%sTotal\n",
nameBuff,
labBuff,
bonusBuff
);
System.out.printf("----%s---%s-----%s-----\n",
nameBuff,
labBuff,
bonusBuff
);
for (int i = 0; i < students.length; i++) {
String thisNameBuff = "";
String thisLabBuff = "";
String thisBonusBuff = "";
// More splitting for loops in half because we cant put the long
// calculated bounds in their own int because can't have more than
// 30 statements within a function. Thank you very very much.
// We all appreciate checkstyle rules.
for (int j = 0; j < (nameBuff.length() + "name".length())
- students[i].getName().length(); j++) {
thisNameBuff += " ";
}
for (int j = 0; j < (labBuff.length() + "lab".length())
- ("" + students[i].getLab()).length(); j++) {
thisLabBuff += " ";
}
for (int j = 0; j < (bonusBuff.length() + "bonus".length())
- ("" + students[i].getBonus()).length(); j++) {
thisBonusBuff += " ";
}
System.out.println(students[i].getName()
+ thisNameBuff
+ students[i].getLab()
+ thisLabBuff
+ students[i].getBonus()
+ thisBonusBuff
+ students[i].getTotal()
);
}
}
}
+100
View File
@@ -0,0 +1,100 @@
package lab3;
/**
* CardGame give a random card.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class CardGame {
enum Rank {
/**
* ace is ace.
*/
ace,
/**
* two is two.
*/
two,
/**
* three is three.
*/
three,
/**
* four is four.
*/
four,
/**
* five is five.
*/
five,
/**
* six is six.
*/
six,
/**
* seven is seven.
*/
seven,
/**
* eight is eight.
*/
eight,
/**
* nine is nine.
*/
nine,
/**
* ten is ten.
*/
ten,
/**
* jack is jack.
*/
jack,
/**
* queen is queen.
*/
queen,
/**
* king is king.
*/
king
}
enum Suit {
/**
* hearts.
*/
hearts,
/**
* diamonds.
*/
diamonds,
/**
* clubs.
*/
clubs,
/**
* spades.
*/
spades
}
/*
* Thank you checkstyle for making things very very clear.
* with the need for javadoc comments on every enum variant.
*/
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
int randomRankChoice = (int) (Math.random() * Rank.values().length);
int randomSuitChoice = (int) (Math.random() * Suit.values().length);
Rank randomRank = Rank.values()[randomRankChoice];
Suit randomSuit = Suit.values()[randomSuitChoice];
System.out.printf("%s of %s", randomRank, randomSuit);
}
}
+46
View File
@@ -0,0 +1,46 @@
package lab3;
/**
* Dice simulate dice rolling.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Dice {
/**
* main program entry point.
* @param args unused
*/
public static void main(String[] args) {
final int die4 = 4;
final int die6 = 6;
final int die8 = 8;
final int die10 = 10;
final int die12 = 12;
final int die20 = 20;
// to get a random number you do:
// (Math.random() * (max - min)) + min;
// this will give a range of min to (max - 1)
int castDie4 = (int) (Math.random() * die4) + 1;
int castDie6 = (int) (Math.random() * die6) + 1;
int castDie8 = (int) (Math.random() * die8) + 1;
int castDie10 = (int) (Math.random() * die10) + 1;
int castDie12 = (int) (Math.random() * die12) + 1;
int castDie20 = (int) (Math.random() * die20) + 1;
int sum = castDie4
+ castDie6
+ castDie8
+ castDie10
+ castDie12
+ castDie20;
System.out.printf("4 sided die: %d\n", castDie4);
System.out.printf("6 sided die: %d\n", castDie6);
System.out.printf("8 sided die: %d\n", castDie8);
System.out.printf("10 sided die: %d\n", castDie10);
System.out.printf("12 sided die: %d\n", castDie12);
System.out.printf("20 sided die: %d\n", castDie20);
System.out.printf("Sum of all dice: %d\n", sum);
}
}
+45
View File
@@ -0,0 +1,45 @@
package lab3;
import java.util.Scanner;
/**
* Distance calculates distance between two points
* using pythagorean theorem.
* @author Braeden Sowinski
* @version 1.0.0
*/
public class Distance {
/**
* main program entry.
* @param args unused
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double x1;
double y1;
double x2;
double y2;
System.out.print("Enter x1 coord: ");
x1 = scan.nextDouble();
System.out.print("Enter y1 coord: ");
y1 = scan.nextDouble();
System.out.print("Enter x2 coord: ");
x2 = scan.nextDouble();
System.out.print("Enter y2 coord: ");
y2 = scan.nextDouble();
scan.close();
double distance = Math.sqrt(Math.pow((x2 - x1), 2)
+ Math.pow((y2 - y1), 2));
// Yes this looks neater than a long single line -- checkstyle
System.out.printf("Distance between"
+ "(%.2f, %.2f) and (%.2f, %.2f): %.2f",
x1, y1, x2, y2, distance);
}
}
+41
View File
@@ -0,0 +1,41 @@
package lab3;
import java.util.Scanner;
/**
* FunWithStrings
* has some fun with strings?
* @author Braeden Sowinski
* @version 1.0.0
*/
public class FunWithStrings {
/**
* main program entry point.
* @param args unused
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String book;
String trimmedBook;
System.out.print("Enter the title of your favourite book: ");
book = scan.nextLine();
trimmedBook = book.trim();
scan.close();
System.out.printf("Book: %s\n", book);
System.out.printf("Title length: %d\n", book.length());
System.out.printf("Trimed title length: %d\n", trimmedBook.length());
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);
// Very clean code here -- checkstyle
int len = trimmedBook.length();
String upperFirst = trimmedBook.substring(0, 1).toUpperCase();
String middleLow = trimmedBook.substring(1, len - 1);
String upperLast = trimmedBook.substring(len - 1, len).toUpperCase();
System.out.printf("Finally: %s\n", upperFirst + middleLow + upperLast);
}
}
+8
View File
@@ -0,0 +1,8 @@
/**
*
*/
/**
*
*/
module lab0 {
}