From b2230558db0ea82ee5cc6e2693472cf1a2b0d468 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Fri, 24 Jan 2025 21:24:00 -0800 Subject: [PATCH] initial commit --- .classpath | 10 ++ .gitignore | 5 + .project | 23 ++++ .settings/org.eclipse.core.resources.prefs | 2 + .settings/org.eclipse.jdt.core.prefs | 11 ++ README.md | 7 ++ src/lab0/HelloWorld.java | 17 +++ src/lab1/Birds.java | 23 ++++ src/lab1/Count.java | 33 ++++++ src/lab1/Hello.java | 38 +++++++ src/lab1/Plus.java | 28 +++++ src/lab1/Poem.java | 22 ++++ src/lab1/Problems.java | 23 ++++ src/lab1/Simple.java | 27 +++++ src/lab2/BaseConvert.java | 46 ++++++++ src/lab2/Circle.java | 54 +++++++++ src/lab2/Paint.java | 49 +++++++++ src/lab2/Prelab.java | 60 ++++++++++ src/lab2/Student.java | 78 +++++++++++++ src/lab2/Students.java | 122 +++++++++++++++++++++ src/lab3/CardGame.java | 100 +++++++++++++++++ src/lab3/Dice.java | 46 ++++++++ src/lab3/Distance.java | 45 ++++++++ src/lab3/FunWithStrings.java | 41 +++++++ src/module-info.java | 8 ++ 25 files changed, 918 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 README.md create mode 100644 src/lab0/HelloWorld.java create mode 100644 src/lab1/Birds.java create mode 100644 src/lab1/Count.java create mode 100644 src/lab1/Hello.java create mode 100644 src/lab1/Plus.java create mode 100644 src/lab1/Poem.java create mode 100644 src/lab1/Problems.java create mode 100644 src/lab1/Simple.java create mode 100644 src/lab2/BaseConvert.java create mode 100644 src/lab2/Circle.java create mode 100644 src/lab2/Paint.java create mode 100644 src/lab2/Prelab.java create mode 100644 src/lab2/Student.java create mode 100644 src/lab2/Students.java create mode 100644 src/lab3/CardGame.java create mode 100644 src/lab3/Dice.java create mode 100644 src/lab3/Distance.java create mode 100644 src/lab3/FunWithStrings.java create mode 100644 src/module-info.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..463d5f9 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f7f3019 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Test files +src/test/* + +# class files +bin/* diff --git a/.project b/.project new file mode 100644 index 0000000..a6b59da --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + comp1510 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + net.sf.eclipsecs.core.CheckstyleBuilder + + + + + + org.eclipse.jdt.core.javanature + net.sf.eclipsecs.core.CheckstyleNature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9a7984b --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..db3845c --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# comp1510 + +All programming methods (comp 1510) at BCIT labs. +2025 + +Follows all, 100% valuable, useful, totally accurate checkstyle rules. + diff --git a/src/lab0/HelloWorld.java b/src/lab0/HelloWorld.java new file mode 100644 index 0000000..d385e5e --- /dev/null +++ b/src/lab0/HelloWorld.java @@ -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!"); + } +} diff --git a/src/lab1/Birds.java b/src/lab1/Birds.java new file mode 100644 index 0000000..bae587e --- /dev/null +++ b/src/lab1/Birds.java @@ -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." + ); + } +} diff --git a/src/lab1/Count.java b/src/lab1/Count.java new file mode 100644 index 0000000..db199bb --- /dev/null +++ b/src/lab1/Count.java @@ -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 + */ diff --git a/src/lab1/Hello.java b/src/lab1/Hello.java new file mode 100644 index 0000000..ed31d9e --- /dev/null +++ b/src/lab1/Hello.java @@ -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" + * + */ diff --git a/src/lab1/Plus.java b/src/lab1/Plus.java new file mode 100644 index 0000000..0fe7a74 --- /dev/null +++ b/src/lab1/Plus.java @@ -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."); + } +} diff --git a/src/lab1/Poem.java b/src/lab1/Poem.java new file mode 100644 index 0000000..b59b5a6 --- /dev/null +++ b/src/lab1/Poem.java @@ -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."); + } +} diff --git a/src/lab1/Problems.java b/src/lab1/Problems.java new file mode 100644 index 0000000..a9909f5 --- /dev/null +++ b/src/lab1/Problems.java @@ -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 diff --git a/src/lab1/Simple.java b/src/lab1/Simple.java new file mode 100644 index 0000000..eb4a259 --- /dev/null +++ b/src/lab1/Simple.java @@ -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 (!) + */ diff --git a/src/lab2/BaseConvert.java b/src/lab2/BaseConvert.java new file mode 100644 index 0000000..76d4f70 --- /dev/null +++ b/src/lab2/BaseConvert.java @@ -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 + ); + } +} diff --git a/src/lab2/Circle.java b/src/lab2/Circle.java new file mode 100644 index 0000000..3299efd --- /dev/null +++ b/src/lab2/Circle.java @@ -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"); + } +} diff --git a/src/lab2/Paint.java b/src/lab2/Paint.java new file mode 100644 index 0000000..e4d65bb --- /dev/null +++ b/src/lab2/Paint.java @@ -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."); + } +} diff --git a/src/lab2/Prelab.java b/src/lab2/Prelab.java new file mode 100644 index 0000000..e901ce6 --- /dev/null +++ b/src/lab2/Prelab.java @@ -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); + } +} diff --git a/src/lab2/Student.java b/src/lab2/Student.java new file mode 100644 index 0000000..381a076 --- /dev/null +++ b/src/lab2/Student.java @@ -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; + } +} diff --git a/src/lab2/Students.java b/src/lab2/Students.java new file mode 100644 index 0000000..bd0c3de --- /dev/null +++ b/src/lab2/Students.java @@ -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() + ); + } + } +} diff --git a/src/lab3/CardGame.java b/src/lab3/CardGame.java new file mode 100644 index 0000000..8ad9a0a --- /dev/null +++ b/src/lab3/CardGame.java @@ -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); + } +} diff --git a/src/lab3/Dice.java b/src/lab3/Dice.java new file mode 100644 index 0000000..362c6a5 --- /dev/null +++ b/src/lab3/Dice.java @@ -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); + } +} diff --git a/src/lab3/Distance.java b/src/lab3/Distance.java new file mode 100644 index 0000000..7431042 --- /dev/null +++ b/src/lab3/Distance.java @@ -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); + } +} diff --git a/src/lab3/FunWithStrings.java b/src/lab3/FunWithStrings.java new file mode 100644 index 0000000..c85653b --- /dev/null +++ b/src/lab3/FunWithStrings.java @@ -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); + } +} diff --git a/src/module-info.java b/src/module-info.java new file mode 100644 index 0000000..8a377ca --- /dev/null +++ b/src/module-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * + */ +module lab0 { +} \ No newline at end of file