From 332733653b27b47656b51c0d0a446d46f00ad9c0 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Tue, 13 Sep 2022 12:29:38 -0500 Subject: [PATCH] Lab7 --- .gitignore | 2 + 03_Sep13_2022/pom.xml | 14 ++++ .../calebfontenot/_sep13_2022/LeapYear.java | 28 ++++++++ .../lab7_calebfontenot/And1.java | 17 +++++ .../lab7_calebfontenot/DivisionQuiz.java | 67 +++++++++++++++++++ .../lab7_calebfontenot/SubtractionQuiz.java | 45 +++++++++++++ 6 files changed, 173 insertions(+) create mode 100644 03_Sep13_2022/pom.xml create mode 100644 03_Sep13_2022/src/main/java/com/calebfontenot/_sep13_2022/LeapYear.java create mode 100644 lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/And1.java create mode 100644 lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/DivisionQuiz.java create mode 100644 lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/SubtractionQuiz.java diff --git a/.gitignore b/.gitignore index 1028231..e3e26f8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /lab5_CalebFontenot/target/ /LabClass_Sep6_CalebFontenot/target/ /lab6_CalebFontenot/target/ +/03_Sep13_2022/target/ +/lab7_CalebFontenot/target/ diff --git a/03_Sep13_2022/pom.xml b/03_Sep13_2022/pom.xml new file mode 100644 index 0000000..fa5c83e --- /dev/null +++ b/03_Sep13_2022/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.calebfontenot._sep13_2022 + 03_Sep13_2022 + 1.0-SNAPSHOT + jar + + UTF-8 + 18 + 18 + com.calebfontenot._sep13_2022.App + + \ No newline at end of file diff --git a/03_Sep13_2022/src/main/java/com/calebfontenot/_sep13_2022/LeapYear.java b/03_Sep13_2022/src/main/java/com/calebfontenot/_sep13_2022/LeapYear.java new file mode 100644 index 0000000..bc86cce --- /dev/null +++ b/03_Sep13_2022/src/main/java/com/calebfontenot/_sep13_2022/LeapYear.java @@ -0,0 +1,28 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template + */ + +package com.calebfontenot._sep13_2022; + +/** + * + * @author caleb + */ +import java.util.Scanner; + +public class LeapYear { + public static void main(String[] args) { + // Create a Scanner + Scanner input = new Scanner(System.in); + System.out.print("Enter a year: "); + int year = input.nextInt(); + + // Check if the year is a leap year + boolean isLeapYear = + (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); + + // Display the result in a message dialog box + System.out.println(year + " is a leap year? " + isLeapYear); + } +} diff --git a/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/And1.java b/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/And1.java new file mode 100644 index 0000000..dadd818 --- /dev/null +++ b/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/And1.java @@ -0,0 +1,17 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package com.calebfontenot.lab7_calebfontenot; + +/** + * + * @author caleb + */ +public class And1 { + public static void main(String[] args) + { + System.out.println("please enter a number between 0 and 10:"); + + } +} diff --git a/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/DivisionQuiz.java b/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/DivisionQuiz.java new file mode 100644 index 0000000..1f88687 --- /dev/null +++ b/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/DivisionQuiz.java @@ -0,0 +1,67 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package com.calebfontenot.lab7_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class DivisionQuiz { + + public static void main(String[] args) + { + // Create scanner + Scanner input = new Scanner(System.in); + // Setup variables + int number1, + number2, + answerQuotient, + answerRemainder; + boolean cheatMode = false; // Used for debugging + + while (true) { + // Get random numbers between 1-100 + number1 = (int) (Math.random() * 100); + number2 = (int) (Math.random() * 100); + + // If number1 < number2, flip them + if (number1 < number2) { + int tmp = number2; + number2 = number1; + number1 = tmp; + } + + //Prompt + if (cheatMode == true) { + System.out.println("CHEAT MODE: the quotient of " + number1 + " / " + number2 + " is " + (number1 / number2)); + } + System.out.print(" What is the quotient of " + number1 + " / " + number2 + "? "); + answerQuotient = input.nextInt(); + if (cheatMode == true) { + System.out.println("CHEAT MODE: the remainder of " + number1 + " % " + number2 + " is " + (number1 % number2)); + } + System.out.print(" What is the remainder of " + number1 + " / " + number2 + "? "); + answerRemainder = input.nextInt(); + + // Check if answers are correct + if ((number1 / number2) == answerQuotient) //Checks the quotient + { + System.out.println("You are correct about the quotient!"); + } else { + System.out.println("You are wrong about the quotient."); + System.out.println("The quotient of " + number1 + " / " + number2 + " is " + (number1 / number2)); + } + if ((number1 % number2) == answerRemainder) //Checks the remainder + { + System.out.println("You are correct about the remainder!"); + } else { + System.out.println("You are wrong about the remainder."); + System.out.println("The remainder of " + number1 + " % " + number2 + " is " + (number1 % number2)); + } + } + } +} diff --git a/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/SubtractionQuiz.java b/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/SubtractionQuiz.java new file mode 100644 index 0000000..8567669 --- /dev/null +++ b/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/SubtractionQuiz.java @@ -0,0 +1,45 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package com.calebfontenot.lab7_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class SubtractionQuiz { + public static void main(String[] args) + { + // Create scanner outside of loop so we don't create it over and over again + Scanner input = new Scanner(System.in); + while(true) { + // 1. Generate two random single-digit integers + int number1 = (int)(Math.random() * 10); + int number2 = (int)(Math.random() * 10); + + // 2. If number < number2, swap number1 with number2 + if (number1 < number2) + { + int temp = number1; + number1 = number2; + number2 = temp; + } + + // 3. Prompt the student to answer "what is number1 - number2?" + System.out.print("What is " + number1 + " - " + number2 + "? "); + int answer = input.nextInt(); + + // 4. Grade the answer and display the result + if (number1 - number2 == answer) + System.out.println("You are correct!"); + else + { + System.out.println("Your answer is wrong."); + System.out.println(number1 + " - " + number2 + "should be" + (number1 - number2)); + } + } + } +}