diff --git a/src/ca/bcit/comp1510/lab11/Average.java b/src/ca/bcit/comp1510/lab11/Average.java new file mode 100644 index 0000000..f2fd3c7 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Average.java @@ -0,0 +1,36 @@ +package ca.bcit.comp1510.lab11; + +import java.lang.NumberFormatException; + +/** + * Average with command line args. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Average { + + /** + * main program entry. + * @param args from command line. + */ + public static void main(String[] args) { + if (args.length == 0) { + System.out.println("No arguments."); + return; + } + + double total = 0.0; + int numbers = 0; + + for (int i = 0; i < args.length; i++) { + try { + total += Double.parseDouble(args[i]); + numbers++; + } catch (NumberFormatException e) { + continue; + } + } + + System.out.println("Average: " + total / numbers); + } +} diff --git a/src/ca/bcit/comp1510/lab11/Coin.java b/src/ca/bcit/comp1510/lab11/Coin.java new file mode 100644 index 0000000..31818ef --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Coin.java @@ -0,0 +1,123 @@ +package ca.bcit.comp1510.lab11; + +/** + * Represents a two-sided coin that can be flipped. Modified over class + * example to use enum. + * + * @author Lewis & Loftus 9e + * @author Bruce Link + * @author BCIT + * @version 2023 + */ +public class Coin implements Lockable { + /** Enumeration type representing sides of a coin. */ + public enum CoinFace { + /** the side of a coin considered tails. */ + Tails, + /** the side of a coin considered heads. */ + Heads + } + + /** Coin's current face showing. */ + private CoinFace face; + + /** key to lock and unlock methods. */ + private int key; + + /** locked indicates if functions can be used. */ + private boolean locked; + + /** + * Constructs a Coin object and flips it to give it a starting value. + */ + public Coin() { + this.key = 0; + this.locked = false; + flip(); + } + + /** + * setKey value. + * @param key to set + */ + public void setKey(int key) { + this.key = key; + } + + /** + * lock Object with key. + * @param keyIn to lock. + * @return success + */ + public boolean lock(int keyIn) { + this.locked = this.key == keyIn ? true : this.locked; + return this.key == keyIn; + } + + /** + * unlock Object with key. + * @param keyIn to unlock. + * @return success + */ + public boolean unlock(int keyIn) { + this.locked = this.key == keyIn ? false : this.locked; + return this.key == keyIn; + } + + /** + * locked Object state. + * @return locked + */ + public boolean locked() { + return this.locked; + } + + /** + * Flips this Coin by randomly choosing a face value. + */ + public void flip() { + if (this.locked) { + return; + } + final double half = 0.5; + if (Math.random() < half) { + face = CoinFace.Heads; + } else { + face = CoinFace.Tails; + } + } + + /** + * returns side of coin as CoinFace type. + * @return current showing face of this coin. + */ + public CoinFace getFace() { + return face; + } + + /** + * set the coin face explicitly. No required check on values as enum + * CoinFace allows no illegal values to be passed. + * @param newFace the new face to show. + */ + public void setFace(CoinFace newFace) { + face = newFace; + } + + /** + * Returns true if the current face of the Coin is heads. + * @return true if current face is heads, else false. + */ + public boolean isHeads() { + return face == CoinFace.Heads; + } + + /** + * Returns the current face value of this Coin as a String. + * @return toString description + */ + public String toString() { + return face.name(); + } +} + diff --git a/src/ca/bcit/comp1510/lab11/Item.java b/src/ca/bcit/comp1510/lab11/Item.java new file mode 100644 index 0000000..562babc --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Item.java @@ -0,0 +1,78 @@ +package ca.bcit.comp1510.lab11; + +import java.text.DecimalFormat; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + /** name of item. */ + private final String name; + + /** price of item. */ + private final double price; + + /** quanitity of item. */ + private final int quantity; + + /** + * Item constructor. + * @param name of item + * @param price of item + * @param quantity of item + */ + public Item(String name, double price, int quantity) { + this.name = name; + this.quantity = quantity; + DecimalFormat format = new DecimalFormat("#0.00"); + this.price = Double.parseDouble(format.format(price)); + } + + /** + * Item constructor with default quantity. + * @param name of item + * @param price of item + */ + public Item(String name, double price) { + this.name = name; + DecimalFormat format = new DecimalFormat("#0.00"); + this.price = Double.parseDouble(format.format(price)); + this.quantity = 1; + } + + /** + * getName of time. + * @return name of item + */ + public String getName() { + return this.name; + } + + /** + * getPrice of item. + * @return price of item + */ + public double getPrice() { + return this.price; + } + + /** + * getQuantity of item. + * @return quantity of item + */ + public int getQuantity() { + return this.quantity; + } + + /** + * toString gives string representation of item. + * @return string of item. + */ + public String toString() { + return this.name + " $" + this.price + + " x" + this.quantity; + } +} diff --git a/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184119-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184119-KMJBCBL.java new file mode 100644 index 0000000..3f6d7f4 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184119-KMJBCBL.java @@ -0,0 +1,5 @@ +package ca.bcit.comp1510.lab11; + +public class Item { + +} diff --git a/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184149-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184149-KMJBCBL.java new file mode 100644 index 0000000..eb25a4a --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184149-KMJBCBL.java @@ -0,0 +1,10 @@ +package ca.bcit.comp1510.lab11; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + +} diff --git a/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184219-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184219-KMJBCBL.java new file mode 100644 index 0000000..b4b90f4 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184219-KMJBCBL.java @@ -0,0 +1,13 @@ +package ca.bcit.comp1510.lab11; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + private final String name; + + private +} diff --git a/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184229-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184229-KMJBCBL.java new file mode 100644 index 0000000..86de715 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184229-KMJBCBL.java @@ -0,0 +1,15 @@ +package ca.bcit.comp1510.lab11; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + private final String name; + + private final double price; + + private final int quantity; +} diff --git a/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184249-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184249-KMJBCBL.java new file mode 100644 index 0000000..343b305 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184249-KMJBCBL.java @@ -0,0 +1,16 @@ +package ca.bcit.comp1510.lab11; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + /** name of item. */ + private final String name; + + private final double price; + + private final int quantity; +} diff --git a/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184309-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184309-KMJBCBL.java new file mode 100644 index 0000000..72e4543 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-184309-KMJBCBL.java @@ -0,0 +1,18 @@ +package ca.bcit.comp1510.lab11; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + /** name of item. */ + private final String name; + + /** price of item. */ + private final double price; + + /** quanitity of item */ + private final int quantity; +} diff --git a/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-185119-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-185119-KMJBCBL.java new file mode 100644 index 0000000..99aac4f --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Item.sync-conflict-20250401-185119-KMJBCBL.java @@ -0,0 +1,83 @@ +package ca.bcit.comp1510.lab11; + +import java.text.DecimalFormat; +import java.util.NumberFormat; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + /** name of item. */ + private final String name; + + /** price of item. */ + private final double price; + + /** quanitity of item. */ + private final int quantity; + + /** + * Item constructor. + * @param name of item + * @param price of item + * @param quantity of item + */ + public Item(String name, double price, int quantity) { + this.name = name; + this.price = price; + this.quantity = quantity; + + + DecimalFormat format = new DecimalFormat("#0.00"); + return Double.parseDouble(format.format(a / this.students.size())); + + this.price = + } + + /** + * Item constructor with default quantity. + * @param name of item + * @param price of item + */ + public Item(String name, double price) { + this.name = name; + this.price = price; + this.quantity = 1; + } + + /** + * getName of time. + * @return name of item + */ + public String getName() { + return this.name; + } + + /** + * getPrice of item. + * @return price of item + */ + public double getPrice() { + return this.price; + } + + /** + * getQuantity of item. + * @return quantity of item + */ + public int getQuantity() { + return this.quantity; + } + + /** + * toString gives string representation of item. + * @return string of item. + */ + public String toString() { + return this.name + " $" + this.price + + " x" + this.quantity; + } +} diff --git a/src/ca/bcit/comp1510/lab11/Lockable.java b/src/ca/bcit/comp1510/lab11/Lockable.java new file mode 100644 index 0000000..82a1c05 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Lockable.java @@ -0,0 +1,35 @@ +package ca.bcit.comp1510.lab11; + +/** + * Lockable does stuff. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public interface Lockable { + + /** + * setKey value. + * @param key to set + */ + void setKey(int key); + + /** + * lock Object with key. + * @param key to lock. + * @return success + */ + boolean lock(int key); + + /** + * unlock Object with key. + * @param key to unlock. + * @return success + */ + boolean unlock(int key); + + /** + * locked Object state. + * @return locked + */ + boolean locked(); +} diff --git a/src/ca/bcit/comp1510/lab11/LockableDriver.java b/src/ca/bcit/comp1510/lab11/LockableDriver.java new file mode 100644 index 0000000..adeb61c --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/LockableDriver.java @@ -0,0 +1,44 @@ +package ca.bcit.comp1510.lab11; + +/** + * LockableDriver drives Lockable Coin. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class LockableDriver { + + /** + * main program entry. + * @param args unused. + */ + public static void main(String[] args) { + Coin coin = new Coin(); + + System.out.println("Coin is " + + (coin.locked() ? "locked" : "unlocked")); + + System.out.println("Face: " + coin.getFace()); + System.out.println("Flipping..."); + coin.flip(); + System.out.println("Face: " + coin.getFace()); + + System.out.println("Locking Coin..."); + final int key = 984757; + coin.setKey(key); + coin.lock(key); + + System.out.println("Flipping..."); + coin.flip(); + System.out.println("Face: " + coin.getFace()); + + System.out.println("No change in face value because " + + "coin is locked and cannot be flipped."); + + System.out.println("Unlocking Coin..."); + coin.unlock(key); + + System.out.println("Flipping..."); + coin.flip(); + System.out.println("Face: " + coin.getFace()); + } +} diff --git a/src/ca/bcit/comp1510/lab11/LockableDriver.sync-conflict-20250401-181112-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/LockableDriver.sync-conflict-20250401-181112-KMJBCBL.java new file mode 100644 index 0000000..f841b18 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/LockableDriver.sync-conflict-20250401-181112-KMJBCBL.java @@ -0,0 +1,19 @@ +package ca.bcit.comp1510.lab11; + +/** + * LockableDriver drives Lockable Coin. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class LockableDriver { + + /** + * main program entry. + * @param args unused. + */ + public static void main(String[] args) { + Coin coin = new Coin(); + + + } +} diff --git a/src/ca/bcit/comp1510/lab11/LockableImplementation.java b/src/ca/bcit/comp1510/lab11/LockableImplementation.java new file mode 100644 index 0000000..2f3d555 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/LockableImplementation.java @@ -0,0 +1,70 @@ +package ca.bcit.comp1510.lab11; + +/** + * LockableImplementation is a demo of + * implementing Lockable interface. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class LockableImplementation implements Lockable { + + /** key of class. */ + private int key; + + /** locked state of class. */ + private boolean locked; + + /** LockableImplementation empty constructor. */ + public LockableImplementation() { + this.key = 0; + this.locked = false; + } + + /** + * setKey value. + * @param key to set + */ + public void setKey(int key) { + this.key = key; + } + + /** + * lock Object with key. + * @param keyIn to lock. + * @return success + */ + public boolean lock(int keyIn) { + this.locked = this.key == keyIn ? true : this.locked; + return this.key == keyIn; + } + + /** + * unlock Object with key. + * @param keyIn to unlock. + * @return success + */ + public boolean unlock(int keyIn) { + this.locked = this.key == keyIn ? false : this.locked; + return this.key == keyIn; + } + + /** + * locked Object state. + * @return locked + */ + public boolean locked() { + return this.locked; + } + + /** + * doSomething as examplet to demo locked. + * @param data string + * */ + public void doSomething(String data) { + if (this.locked) { + return; + } + + System.out.println("Doing something with " + data); + } +} diff --git a/src/ca/bcit/comp1510/lab11/ReverseArray.java b/src/ca/bcit/comp1510/lab11/ReverseArray.java new file mode 100644 index 0000000..5c70dda --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/ReverseArray.java @@ -0,0 +1,83 @@ +package ca.bcit.comp1510.lab11; + +import java.util.Scanner; +import java.util.Arrays; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + + /** + * readValidInt reads and validates an integer. + * @param msg to print; + * @param scan to read input + * @return validated int + */ + private static int readValidInt(String msg, Scanner scan) { + int number = 0; + boolean valid = false; + + do { + System.out.print(msg); + + if (!scan.hasNextInt()) { + System.out.println(scan.next() + " is not a valid number.\n"); + continue; + } + + number = scan.nextInt(); + valid = true; + + } while (!valid); + + return number; + } + + /** + * reverseIntArray reverses an array of ints. + * @param arr of ints. + * @return reversed array of ints. + */ + private static int[] reverseIntArray(int[] arr) { + int n; + for (int i = 0; i < arr.length / 2; i++) { + n = arr[arr.length - 1 - i]; + arr[arr.length - 1 - i] = arr[i]; + arr[i] = n; + } + + return arr; + } + + /** + * main program entry. + * @param args unused + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + int length = readValidInt( + "Please enter the length for the array: ", + scan + ); + + int[] arr = new int[length]; + + for (int i = 0; i < length; i++) { + int num = readValidInt( + "Please enter a number: ", + scan + ); + arr[i] = num; + } + + System.out.println(Arrays.toString(arr)); + + arr = reverseIntArray(arr); + + System.out.println(Arrays.toString(arr)); + } +} diff --git a/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-181512-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-181512-KMJBCBL.java new file mode 100644 index 0000000..18e7256 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-181512-KMJBCBL.java @@ -0,0 +1,8 @@ +package ca.bcit.comp1510.lab11; + +/** + * ReverseArray is self explanitory. + */ +public class ReverseArray { + +} diff --git a/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-181532-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-181532-KMJBCBL.java new file mode 100644 index 0000000..c970026 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-181532-KMJBCBL.java @@ -0,0 +1,10 @@ +package ca.bcit.comp1510.lab11; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + +} diff --git a/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-181552-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-181552-KMJBCBL.java new file mode 100644 index 0000000..f3551a1 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-181552-KMJBCBL.java @@ -0,0 +1,11 @@ +package ca.bcit.comp1510.lab11; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + + +} diff --git a/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-182432-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-182432-KMJBCBL.java new file mode 100644 index 0000000..6465eda --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-182432-KMJBCBL.java @@ -0,0 +1,13 @@ +package ca.bcit.comp1510.lab11; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + + public static void main(String[] args) { + + } +} diff --git a/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-183019-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-183019-KMJBCBL.java new file mode 100644 index 0000000..521bd84 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-183019-KMJBCBL.java @@ -0,0 +1,58 @@ +package ca.bcit.comp1510.lab11; + +import java.util.Scanner; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + + /** + * readValidInt reads and validates an integer. + * @param msg to print; + * @param scan to read input + * @return validated int + */ + private static int readValidInt(String msg, Scanner scan) { + int number = 0; + boolean valid = false; + + do { + System.out.print(msg); + + if (!scan.hasNextInt()) { + System.out.println(scan.next() + " is not a valid number.\n"); + continue; + } + + number = scan.nextInt(); + valid = true; + + } while (!valid); + + return number; + } + + /** + * main program entry. + * @param args unused + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + int length = readValidInt( + "Please enter the length for the array: ", + scan + ); + + for (int i = 0; i < length; i++) { + int num = readValidInt( + "Please enter a number: ", + scan + ); + + } + } +} diff --git a/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-183909-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-183909-KMJBCBL.java new file mode 100644 index 0000000..4de444a --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/ReverseArray.sync-conflict-20250401-183909-KMJBCBL.java @@ -0,0 +1,85 @@ +package ca.bcit.comp1510.lab11; + +import java.util.Scanner; +import java.util.Arrays; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + + /** + * readValidInt reads and validates an integer. + * @param msg to print; + * @param scan to read input + * @return validated int + */ + private static int readValidInt(String msg, Scanner scan) { + int number = 0; + boolean valid = false; + + do { + System.out.print(msg); + + if (!scan.hasNextInt()) { + System.out.println(scan.next() + " is not a valid number.\n"); + continue; + } + + number = scan.nextInt(); + valid = true; + + } while (!valid); + + return number; + } + + /** + * reverseIntArray reverses an array of ints. + * @param arr of ints. + * @return reversed array of ints. + */ + private static int[] reverseIntArray(int[] arr) { + int[] reversed = new int[arr.length]; + + int n; + for (int i = 0; i < arr.length / 2; i++) { + n = arr[arr.length - i]; + arr[arr.length - i] = arr[i]; + arr[i] = n; + } + + return reversed; + } + + /** + * main program entry. + * @param args unused + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + int length = readValidInt( + "Please enter the length for the array: ", + scan + ); + + int[] arr = new int[length]; + + for (int i = 0; i < length; i++) { + int num = readValidInt( + "Please enter a number: ", + scan + ); + arr[i] = num; + } + + System.out.println(Arrays.toString(arr)); + + arr = reverseIntArray(arr); + + System.out.println(Arrays.toString(arr)); + } +} diff --git a/src/ca/bcit/comp1510/lab11/Shopping.java b/src/ca/bcit/comp1510/lab11/Shopping.java new file mode 100644 index 0000000..3f81f16 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Shopping.java @@ -0,0 +1,96 @@ +package ca.bcit.comp1510.lab11; + +import java.util.Scanner; + +/** + * Shopping cart driver. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Shopping { + + /** + * readValidInt reads and validates an integer. + * @param msg to print; + * @param scan to read input + * @return validated int + */ + private static int readValidInt(String msg, Scanner scan) { + int number = 0; + boolean valid = false; + + do { + System.out.print(msg); + + if (!scan.hasNextInt()) { + System.out.println(scan.next() + " is not a valid number.\n"); + continue; + } + + number = scan.nextInt(); + valid = true; + + } while (!valid); + + return number; + } + + /** + * main program entry. + * @param args unused. + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + + final double burgerPrice = 8.16; + final double friesPrice = 3.25; + final double cokePrice = 2.75; + + int burgers = 0; + int fries = 0; + int cokes = 0; + + final int finish = 4; + int input = 0; + + final String msg = "Select an item to add to cart:\n" + + "(1). Burger $8.16\n" + + "(2). Fries $3.25\n" + + "(3). Coke $2.75\n" + + "(4). Proceed to Checkout\n" + + "> "; + + final int startSize = 3; + Transaction cart = new Transaction(startSize); + + final int t = 3; + final int f = 4; + + do { + input = readValidInt(msg, scan); + + switch (input) { + case 1: + cart.addToCart("Burger", burgerPrice, 1); + break; + case 2: + cart.addToCart("fries", fries, 1); + break; + case t: + cart.addToCart(new Item("Coke", cokePrice, 1)); + break; + case f: + System.out.println("Checking Out..."); + System.out.println(cart.getCount() + " items comes to " + + cart.getTotalPrice()); + break; + default: + System.out.println(input + " is not a valid input."); + break; + } + } while (input != finish); + + scan.close(); + } +} diff --git a/src/ca/bcit/comp1510/lab11/Shopping.sync-conflict-20250401-191950-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Shopping.sync-conflict-20250401-191950-KMJBCBL.java new file mode 100644 index 0000000..22d8961 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Shopping.sync-conflict-20250401-191950-KMJBCBL.java @@ -0,0 +1,5 @@ +package ca.bcit.comp1510.lab11; + +public class Shopping { + +} diff --git a/src/ca/bcit/comp1510/lab11/Shopping.sync-conflict-20250401-192000-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Shopping.sync-conflict-20250401-192000-KMJBCBL.java new file mode 100644 index 0000000..ddc9f6a --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Shopping.sync-conflict-20250401-192000-KMJBCBL.java @@ -0,0 +1,10 @@ +package ca.bcit.comp1510.lab11; + +/** + * Shopping cart driver. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Shopping { + +} diff --git a/src/ca/bcit/comp1510/lab11/Shopping.sync-conflict-20250401-192200-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Shopping.sync-conflict-20250401-192200-KMJBCBL.java new file mode 100644 index 0000000..7f375ea --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Shopping.sync-conflict-20250401-192200-KMJBCBL.java @@ -0,0 +1,18 @@ +package ca.bcit.comp1510.lab11; + +/** + * Shopping cart driver. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Shopping { + + /** + * main program entry. + * @param args unused. + */ + public static void main(String[] args) { + final int burgerPrice = 3.16; + Item burger = new Item("Burger", 8.16, 1); + } +} diff --git a/src/ca/bcit/comp1510/lab11/Transaction.java b/src/ca/bcit/comp1510/lab11/Transaction.java new file mode 100644 index 0000000..da9a99f --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Transaction.java @@ -0,0 +1,90 @@ +package ca.bcit.comp1510.lab11; + +/** + * Transaction of items. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Transaction { + + /** items in transaction. */ + private Item[] items; + + /** totalPrice of transaction. */ + private double totalPrice; + + /** itemCount of transaction. */ + private int itemCount; + + /** + * Tramsaction constructor. + * @param size of items; + */ + public Transaction(int size) { + this.items = new Item[size]; + this.totalPrice = 0; + this.itemCount = 0; + } + + /** + * addToCart creates an item to add to cart. + * @param name of item + * @param price of item + * @param quantity of item + */ + public void addToCart(String name, double price, int quantity) { + Item item = new Item(name, price, quantity); + + if (this.itemCount == this.items.length) { + increaseSize(); + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += price * quantity; + } + + /** + * addToCart adds existing item to cart. + * @param item to add + */ + public void addToCart(Item item) { + if (this.itemCount == this.items.length) { + increaseSize(); + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += item.getPrice() * item.getQuantity(); + } + + /** increaseSize of cart. */ + public void increaseSize() { + final int up = 3; + Item[] updatedItems = new Item[this.items.length + up]; + + for (int i = 0; i < this.itemCount; i++) { + updatedItems[i] = this.items[i]; + } + + this.items = updatedItems; + } + + /** + * getTotalPrice gets total price. + * @return total price + */ + public double getTotalPrice() { + return this.totalPrice; + } + + /** + * getCount of items. + * @return number of items. + */ + public int getCount() { + return this.itemCount; + } +} diff --git a/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190059-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190059-KMJBCBL.java new file mode 100644 index 0000000..6145a12 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190059-KMJBCBL.java @@ -0,0 +1,32 @@ +package ca.bcit.comp1510.lab11; + +/** + * Transaction of items. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Transaction { + + /** items in transaction. */ + private Item[] items; + + /** totalPrice of transaction. */ + private double totalPrice; + + /** itemCount of transaction. */ + private int itemCount; + + /** + * Tramsaction constructor. + * @param size of items; + */ + public Transaction(int size) { + this.items = new Item[size]; + this.totalPrice = 0; + this.itemCount = 0; + } + + public void addToCart(String name, double price, int quantity) { + Item item = new Item(name, price, quantity); + } +} diff --git a/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190602-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190602-KMJBCBL.java new file mode 100644 index 0000000..fe4668b --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190602-KMJBCBL.java @@ -0,0 +1,63 @@ +package ca.bcit.comp1510.lab11; + +/** + * Transaction of items. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Transaction { + + /** items in transaction. */ + private Item[] items; + + /** totalPrice of transaction. */ + private double totalPrice; + + /** itemCount of transaction. */ + private int itemCount; + + /** + * Tramsaction constructor. + * @param size of items; + */ + public Transaction(int size) { + this.items = new Item[size]; + this.totalPrice = 0; + this.itemCount = 0; + } + + /** + * addToCart creates an item to add to cart. + * @param name of item + * @param price of item + * @param quantity of item + */ + public void addToCart(String name, double price, int quantity) { + Item item = new Item(name, price, quantity); + + if (this.itemCount == this.items.length) { + + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += price * quantity; + } + + /** + * addToCart adds existing item to cart. + * @param item to add + */ + public void addToCart(Item item) { + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += item.getPrice() * item.getQuantity(); + } + + /** increaseSize of cart. */ + public void increaseSize() { + + } +} diff --git a/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190827-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190827-KMJBCBL.java new file mode 100644 index 0000000..c2b18ed --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190827-KMJBCBL.java @@ -0,0 +1,72 @@ +package ca.bcit.comp1510.lab11; + +/** + * Transaction of items. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Transaction { + + /** items in transaction. */ + private Item[] items; + + /** totalPrice of transaction. */ + private double totalPrice; + + /** itemCount of transaction. */ + private int itemCount; + + /** + * Tramsaction constructor. + * @param size of items; + */ + public Transaction(int size) { + this.items = new Item[size]; + this.totalPrice = 0; + this.itemCount = 0; + } + + /** + * addToCart creates an item to add to cart. + * @param name of item + * @param price of item + * @param quantity of item + */ + public void addToCart(String name, double price, int quantity) { + Item item = new Item(name, price, quantity); + + if (this.itemCount == this.items.length) { + increaseSize(); + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += price * quantity; + } + + /** + * addToCart adds existing item to cart. + * @param item to add + */ + public void addToCart(Item item) { + if (this.itemCount == this.items.length) { + increaseSize(); + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += item.getPrice() * item.getQuantity(); + } + + /** increaseSize of cart. */ + public void increaseSize() { + final int up = 3; + Item[] updatedItems = new Item[this.items.length + up]; + + for (int i = 0; i < this.itemCount; i++) { + updatedItems[i] = this.items[i]; + } + } +} diff --git a/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190849-KMJBCBL.java b/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190849-KMJBCBL.java new file mode 100644 index 0000000..fdf0ef3 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/Transaction.sync-conflict-20250401-190849-KMJBCBL.java @@ -0,0 +1,74 @@ +package ca.bcit.comp1510.lab11; + +/** + * Transaction of items. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Transaction { + + /** items in transaction. */ + private Item[] items; + + /** totalPrice of transaction. */ + private double totalPrice; + + /** itemCount of transaction. */ + private int itemCount; + + /** + * Tramsaction constructor. + * @param size of items; + */ + public Transaction(int size) { + this.items = new Item[size]; + this.totalPrice = 0; + this.itemCount = 0; + } + + /** + * addToCart creates an item to add to cart. + * @param name of item + * @param price of item + * @param quantity of item + */ + public void addToCart(String name, double price, int quantity) { + Item item = new Item(name, price, quantity); + + if (this.itemCount == this.items.length) { + increaseSize(); + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += price * quantity; + } + + /** + * addToCart adds existing item to cart. + * @param item to add + */ + public void addToCart(Item item) { + if (this.itemCount == this.items.length) { + increaseSize(); + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += item.getPrice() * item.getQuantity(); + } + + /** increaseSize of cart. */ + public void increaseSize() { + final int up = 3; + Item[] updatedItems = new Item[this.items.length + up]; + + for (int i = 0; i < this.itemCount; i++) { + updatedItems[i] = this.items[i]; + } + + this.items = updatedItems; + } +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Item.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Item.java.tmp new file mode 100644 index 0000000..562babc --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Item.java.tmp @@ -0,0 +1,78 @@ +package ca.bcit.comp1510.lab11; + +import java.text.DecimalFormat; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + /** name of item. */ + private final String name; + + /** price of item. */ + private final double price; + + /** quanitity of item. */ + private final int quantity; + + /** + * Item constructor. + * @param name of item + * @param price of item + * @param quantity of item + */ + public Item(String name, double price, int quantity) { + this.name = name; + this.quantity = quantity; + DecimalFormat format = new DecimalFormat("#0.00"); + this.price = Double.parseDouble(format.format(price)); + } + + /** + * Item constructor with default quantity. + * @param name of item + * @param price of item + */ + public Item(String name, double price) { + this.name = name; + DecimalFormat format = new DecimalFormat("#0.00"); + this.price = Double.parseDouble(format.format(price)); + this.quantity = 1; + } + + /** + * getName of time. + * @return name of item + */ + public String getName() { + return this.name; + } + + /** + * getPrice of item. + * @return price of item + */ + public double getPrice() { + return this.price; + } + + /** + * getQuantity of item. + * @return quantity of item + */ + public int getQuantity() { + return this.quantity; + } + + /** + * toString gives string representation of item. + * @return string of item. + */ + public String toString() { + return this.name + " $" + this.price + + " x" + this.quantity; + } +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184119-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184119-KMJBCBL.java.tmp new file mode 100644 index 0000000..3f6d7f4 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184119-KMJBCBL.java.tmp @@ -0,0 +1,5 @@ +package ca.bcit.comp1510.lab11; + +public class Item { + +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184149-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184149-KMJBCBL.java.tmp new file mode 100644 index 0000000..eb25a4a --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184149-KMJBCBL.java.tmp @@ -0,0 +1,10 @@ +package ca.bcit.comp1510.lab11; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184219-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184219-KMJBCBL.java.tmp new file mode 100644 index 0000000..b4b90f4 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184219-KMJBCBL.java.tmp @@ -0,0 +1,13 @@ +package ca.bcit.comp1510.lab11; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + private final String name; + + private +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184229-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184229-KMJBCBL.java.tmp new file mode 100644 index 0000000..86de715 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184229-KMJBCBL.java.tmp @@ -0,0 +1,15 @@ +package ca.bcit.comp1510.lab11; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + private final String name; + + private final double price; + + private final int quantity; +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184249-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184249-KMJBCBL.java.tmp new file mode 100644 index 0000000..343b305 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184249-KMJBCBL.java.tmp @@ -0,0 +1,16 @@ +package ca.bcit.comp1510.lab11; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + /** name of item. */ + private final String name; + + private final double price; + + private final int quantity; +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184309-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184309-KMJBCBL.java.tmp new file mode 100644 index 0000000..72e4543 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-184309-KMJBCBL.java.tmp @@ -0,0 +1,18 @@ +package ca.bcit.comp1510.lab11; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + /** name of item. */ + private final String name; + + /** price of item. */ + private final double price; + + /** quanitity of item */ + private final int quantity; +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-185119-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-185119-KMJBCBL.java.tmp new file mode 100644 index 0000000..99aac4f --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Item.sync-conflict-20250401-185119-KMJBCBL.java.tmp @@ -0,0 +1,83 @@ +package ca.bcit.comp1510.lab11; + +import java.text.DecimalFormat; +import java.util.NumberFormat; + +/** + * Item class for POS System. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Item { + + /** name of item. */ + private final String name; + + /** price of item. */ + private final double price; + + /** quanitity of item. */ + private final int quantity; + + /** + * Item constructor. + * @param name of item + * @param price of item + * @param quantity of item + */ + public Item(String name, double price, int quantity) { + this.name = name; + this.price = price; + this.quantity = quantity; + + + DecimalFormat format = new DecimalFormat("#0.00"); + return Double.parseDouble(format.format(a / this.students.size())); + + this.price = + } + + /** + * Item constructor with default quantity. + * @param name of item + * @param price of item + */ + public Item(String name, double price) { + this.name = name; + this.price = price; + this.quantity = 1; + } + + /** + * getName of time. + * @return name of item + */ + public String getName() { + return this.name; + } + + /** + * getPrice of item. + * @return price of item + */ + public double getPrice() { + return this.price; + } + + /** + * getQuantity of item. + * @return quantity of item + */ + public int getQuantity() { + return this.quantity; + } + + /** + * toString gives string representation of item. + * @return string of item. + */ + public String toString() { + return this.name + " $" + this.price + + " x" + this.quantity; + } +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~LockableDriver.sync-conflict-20250401-181112-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~LockableDriver.sync-conflict-20250401-181112-KMJBCBL.java.tmp new file mode 100644 index 0000000..f841b18 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~LockableDriver.sync-conflict-20250401-181112-KMJBCBL.java.tmp @@ -0,0 +1,19 @@ +package ca.bcit.comp1510.lab11; + +/** + * LockableDriver drives Lockable Coin. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class LockableDriver { + + /** + * main program entry. + * @param args unused. + */ + public static void main(String[] args) { + Coin coin = new Coin(); + + + } +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.java.tmp new file mode 100644 index 0000000..dadb585 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.java.tmp @@ -0,0 +1,85 @@ +package ca.bcit.comp1510.lab11; + +import java.util.Scanner; +import java.util.Arrays; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + + /** + * readValidInt reads and validates an integer. + * @param msg to print; + * @param scan to read input + * @return validated int + */ + private static int readValidInt(String msg, Scanner scan) { + int number = 0; + boolean valid = false; + + do { + System.out.print(msg); + + if (!scan.hasNextInt()) { + System.out.println(scan.next() + " is not a valid number.\n"); + continue; + } + + number = scan.nextInt(); + valid = true; + + } while (!valid); + + return number; + } + + /** + * reverseIntArray reverses an array of ints. + * @param arr of ints. + * @return reversed array of ints. + */ + private static int[] reverseIntArray(int[] arr) { + int[] reversed = new int[arr.length]; + + int n; + for (int i = 0; i < arr.length / 2; i++) { + n = arr[arr.length - 1 - i]; + arr[arr.length - 1 - i] = arr[i]; + arr[i] = n; + } + + return reversed; + } + + /** + * main program entry. + * @param args unused + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + int length = readValidInt( + "Please enter the length for the array: ", + scan + ); + + int[] arr = new int[length]; + + for (int i = 0; i < length; i++) { + int num = readValidInt( + "Please enter a number: ", + scan + ); + arr[i] = num; + } + + System.out.println(Arrays.toString(arr)); + + arr = reverseIntArray(arr); + + System.out.println(Arrays.toString(arr)); + } +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-181512-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-181512-KMJBCBL.java.tmp new file mode 100644 index 0000000..18e7256 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-181512-KMJBCBL.java.tmp @@ -0,0 +1,8 @@ +package ca.bcit.comp1510.lab11; + +/** + * ReverseArray is self explanitory. + */ +public class ReverseArray { + +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-181532-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-181532-KMJBCBL.java.tmp new file mode 100644 index 0000000..c970026 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-181532-KMJBCBL.java.tmp @@ -0,0 +1,10 @@ +package ca.bcit.comp1510.lab11; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-181552-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-181552-KMJBCBL.java.tmp new file mode 100644 index 0000000..f3551a1 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-181552-KMJBCBL.java.tmp @@ -0,0 +1,11 @@ +package ca.bcit.comp1510.lab11; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + + +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-183019-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-183019-KMJBCBL.java.tmp new file mode 100644 index 0000000..521bd84 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-183019-KMJBCBL.java.tmp @@ -0,0 +1,58 @@ +package ca.bcit.comp1510.lab11; + +import java.util.Scanner; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + + /** + * readValidInt reads and validates an integer. + * @param msg to print; + * @param scan to read input + * @return validated int + */ + private static int readValidInt(String msg, Scanner scan) { + int number = 0; + boolean valid = false; + + do { + System.out.print(msg); + + if (!scan.hasNextInt()) { + System.out.println(scan.next() + " is not a valid number.\n"); + continue; + } + + number = scan.nextInt(); + valid = true; + + } while (!valid); + + return number; + } + + /** + * main program entry. + * @param args unused + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + int length = readValidInt( + "Please enter the length for the array: ", + scan + ); + + for (int i = 0; i < length; i++) { + int num = readValidInt( + "Please enter a number: ", + scan + ); + + } + } +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-183909-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-183909-KMJBCBL.java.tmp new file mode 100644 index 0000000..4de444a --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~ReverseArray.sync-conflict-20250401-183909-KMJBCBL.java.tmp @@ -0,0 +1,85 @@ +package ca.bcit.comp1510.lab11; + +import java.util.Scanner; +import java.util.Arrays; + +/** + * ReverseArray is self explanitory. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class ReverseArray { + + /** + * readValidInt reads and validates an integer. + * @param msg to print; + * @param scan to read input + * @return validated int + */ + private static int readValidInt(String msg, Scanner scan) { + int number = 0; + boolean valid = false; + + do { + System.out.print(msg); + + if (!scan.hasNextInt()) { + System.out.println(scan.next() + " is not a valid number.\n"); + continue; + } + + number = scan.nextInt(); + valid = true; + + } while (!valid); + + return number; + } + + /** + * reverseIntArray reverses an array of ints. + * @param arr of ints. + * @return reversed array of ints. + */ + private static int[] reverseIntArray(int[] arr) { + int[] reversed = new int[arr.length]; + + int n; + for (int i = 0; i < arr.length / 2; i++) { + n = arr[arr.length - i]; + arr[arr.length - i] = arr[i]; + arr[i] = n; + } + + return reversed; + } + + /** + * main program entry. + * @param args unused + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + int length = readValidInt( + "Please enter the length for the array: ", + scan + ); + + int[] arr = new int[length]; + + for (int i = 0; i < length; i++) { + int num = readValidInt( + "Please enter a number: ", + scan + ); + arr[i] = num; + } + + System.out.println(Arrays.toString(arr)); + + arr = reverseIntArray(arr); + + System.out.println(Arrays.toString(arr)); + } +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Shopping.sync-conflict-20250401-192000-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Shopping.sync-conflict-20250401-192000-KMJBCBL.java.tmp new file mode 100644 index 0000000..ddc9f6a --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Shopping.sync-conflict-20250401-192000-KMJBCBL.java.tmp @@ -0,0 +1,10 @@ +package ca.bcit.comp1510.lab11; + +/** + * Shopping cart driver. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Shopping { + +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Transaction.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Transaction.java.tmp new file mode 100644 index 0000000..c2b18ed --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Transaction.java.tmp @@ -0,0 +1,72 @@ +package ca.bcit.comp1510.lab11; + +/** + * Transaction of items. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Transaction { + + /** items in transaction. */ + private Item[] items; + + /** totalPrice of transaction. */ + private double totalPrice; + + /** itemCount of transaction. */ + private int itemCount; + + /** + * Tramsaction constructor. + * @param size of items; + */ + public Transaction(int size) { + this.items = new Item[size]; + this.totalPrice = 0; + this.itemCount = 0; + } + + /** + * addToCart creates an item to add to cart. + * @param name of item + * @param price of item + * @param quantity of item + */ + public void addToCart(String name, double price, int quantity) { + Item item = new Item(name, price, quantity); + + if (this.itemCount == this.items.length) { + increaseSize(); + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += price * quantity; + } + + /** + * addToCart adds existing item to cart. + * @param item to add + */ + public void addToCart(Item item) { + if (this.itemCount == this.items.length) { + increaseSize(); + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += item.getPrice() * item.getQuantity(); + } + + /** increaseSize of cart. */ + public void increaseSize() { + final int up = 3; + Item[] updatedItems = new Item[this.items.length + up]; + + for (int i = 0; i < this.itemCount; i++) { + updatedItems[i] = this.items[i]; + } + } +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Transaction.sync-conflict-20250401-190059-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Transaction.sync-conflict-20250401-190059-KMJBCBL.java.tmp new file mode 100644 index 0000000..6145a12 --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Transaction.sync-conflict-20250401-190059-KMJBCBL.java.tmp @@ -0,0 +1,32 @@ +package ca.bcit.comp1510.lab11; + +/** + * Transaction of items. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Transaction { + + /** items in transaction. */ + private Item[] items; + + /** totalPrice of transaction. */ + private double totalPrice; + + /** itemCount of transaction. */ + private int itemCount; + + /** + * Tramsaction constructor. + * @param size of items; + */ + public Transaction(int size) { + this.items = new Item[size]; + this.totalPrice = 0; + this.itemCount = 0; + } + + public void addToCart(String name, double price, int quantity) { + Item item = new Item(name, price, quantity); + } +} diff --git a/src/ca/bcit/comp1510/lab11/~syncthing~Transaction.sync-conflict-20250401-190827-KMJBCBL.java.tmp b/src/ca/bcit/comp1510/lab11/~syncthing~Transaction.sync-conflict-20250401-190827-KMJBCBL.java.tmp new file mode 100644 index 0000000..c2b18ed --- /dev/null +++ b/src/ca/bcit/comp1510/lab11/~syncthing~Transaction.sync-conflict-20250401-190827-KMJBCBL.java.tmp @@ -0,0 +1,72 @@ +package ca.bcit.comp1510.lab11; + +/** + * Transaction of items. + * @author Braeden Sowinski + * @version 1.0.0 + */ +public class Transaction { + + /** items in transaction. */ + private Item[] items; + + /** totalPrice of transaction. */ + private double totalPrice; + + /** itemCount of transaction. */ + private int itemCount; + + /** + * Tramsaction constructor. + * @param size of items; + */ + public Transaction(int size) { + this.items = new Item[size]; + this.totalPrice = 0; + this.itemCount = 0; + } + + /** + * addToCart creates an item to add to cart. + * @param name of item + * @param price of item + * @param quantity of item + */ + public void addToCart(String name, double price, int quantity) { + Item item = new Item(name, price, quantity); + + if (this.itemCount == this.items.length) { + increaseSize(); + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += price * quantity; + } + + /** + * addToCart adds existing item to cart. + * @param item to add + */ + public void addToCart(Item item) { + if (this.itemCount == this.items.length) { + increaseSize(); + } + + this.items[itemCount] = item; + this.itemCount++; + + this.totalPrice += item.getPrice() * item.getQuantity(); + } + + /** increaseSize of cart. */ + public void increaseSize() { + final int up = 3; + Item[] updatedItems = new Item[this.items.length + up]; + + for (int i = 0; i < this.itemCount; i++) { + updatedItems[i] = this.items[i]; + } + } +}