From 7a90c4c23f9244114c66deaa5c2f7ad3b49a550d Mon Sep 17 00:00:00 2001 From: Cameron Seamons Date: Sun, 4 Jan 2026 18:56:38 -0700 Subject: [PATCH] moved small projects into one project folder --- practice_projects/src/Main.java | 7 +++ practice_projects/src/ifStatements.java | 62 +++++++++++++++++++ .../src/madLibs.java | 4 +- practice_projects/src/shoppingCart.java | 45 ++++++++++++++ 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 practice_projects/src/Main.java create mode 100644 practice_projects/src/ifStatements.java rename madLibs/src/Main.java => practice_projects/src/madLibs.java (91%) create mode 100644 practice_projects/src/shoppingCart.java diff --git a/practice_projects/src/Main.java b/practice_projects/src/Main.java new file mode 100644 index 0000000..c42c664 --- /dev/null +++ b/practice_projects/src/Main.java @@ -0,0 +1,7 @@ +public class Main { + + public static void main(String[] args) { + + + } +} \ No newline at end of file diff --git a/practice_projects/src/ifStatements.java b/practice_projects/src/ifStatements.java new file mode 100644 index 0000000..516a4f2 --- /dev/null +++ b/practice_projects/src/ifStatements.java @@ -0,0 +1,62 @@ +import java.util.Scanner; + +public class ifStatements { + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + + String name; + int age; + String isStudent; + + System.out.print("Enter your name: "); + name = scanner.nextLine(); + + System.out.print("Enter your age: "); + age = scanner.nextInt(); + scanner.nextLine(); + + System.out.print("Are you a student (true/false): "); + isStudent = scanner.nextLine(); + + // Check if user entered a name + if(name.isEmpty()){ + System.out.println("You didn't enter your name! 😡"); + } + else{ + // Capitalize their name + name = name.substring(0,1).toUpperCase() + name.substring(1).toLowerCase(); + System.out.println("Hello " + name + "! 😀"); + } + + // Place user into their age group and respond accordingly + if(age >= 65){ + System.out.println("You are a senior! 👴"); + } + else if(age >= 18){ + System.out.println("You are an adult! 🧑"); + } + else if(age < 0){ + System.out.println("You haven't been born yet! 👼"); + } + else if(age == 0){ + System.out.println("You are a baby! 👶"); + } + else{ + System.out.println("You are a child! 🧒"); + } + + // normalize the student variable + String studentInput = isStudent.trim().toLowerCase(); + + // Greet user as a student or not + if(studentInput.equals("true") || studentInput.equals("t")){ + System.out.println("You are a student! 🏫"); + } + else{ + System.out.println("You are NOT a student 🏢"); + } + + scanner.close(); + } +} \ No newline at end of file diff --git a/madLibs/src/Main.java b/practice_projects/src/madLibs.java similarity index 91% rename from madLibs/src/Main.java rename to practice_projects/src/madLibs.java index 524679e..7b7c59f 100644 --- a/madLibs/src/Main.java +++ b/practice_projects/src/madLibs.java @@ -1,6 +1,6 @@ import java.util.Scanner; -public class Main { +public class madLibs { public static void main(String[] args){ @@ -23,7 +23,7 @@ public class Main { System.out.print("Enter an adjective (description): "); adjective3 = scanner.nextLine(); - System.out.println("Today I went to a " + adjective1 + " zoo"); + System.out.println("\nToday I went to a " + adjective1 + " zoo"); System.out.println("In an exhibit, I saw a " + noun1 + "."); System.out.println(noun1 + " was " + adjective2 + " and " + verb1 + "!"); System.out.println("I was " + adjective3 + "!"); diff --git a/practice_projects/src/shoppingCart.java b/practice_projects/src/shoppingCart.java new file mode 100644 index 0000000..d91eca6 --- /dev/null +++ b/practice_projects/src/shoppingCart.java @@ -0,0 +1,45 @@ +import java.util.Scanner; + +public class shoppingCart { + + public static void main(String[] args){ + + Scanner scanner = new Scanner(System.in); + + // Declare variables + String item; + double price; + int quantity; + double total; + + // Get item from User + System.out.print("What item would you like to buy?: "); + item = scanner.nextLine(); + + // Get price from User + System.out.print("What is the price for each?: "); + price = scanner.nextDouble(); + + // Get quantity from User + System.out.print("How many would you like?: "); + quantity = scanner.nextInt(); + + // Calculate total + total = price * quantity; + + + // Print out their order + // Check if one item or more to give correct print statement + if (quantity == 1) { + System.out.println("\nYou have bought " + quantity + " " + item); + } + else { + System.out.println("You have bought " + quantity + " " + item + "s"); + } + + // Print their total + System.out.println("Your total is $" + total); + + scanner.close(); + } +}