From fd4d12befa9a60af222e207997ff6ec204135a2d Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Thu, 15 Sep 2022 12:41:34 -0500 Subject: [PATCH] MP2 Progress --- .gitignore | 1 + MP2_CalebFontenot/pom.xml | 14 +++++ .../mp2_calebfontenot/CheckIBSN_10.java | 58 +++++++++++++++++++ .../mp2_calebfontenot/RandomNumber.java | 43 ++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 MP2_CalebFontenot/pom.xml create mode 100644 MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/CheckIBSN_10.java create mode 100644 MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RandomNumber.java diff --git a/.gitignore b/.gitignore index e3e26f8..7a04d75 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /lab6_CalebFontenot/target/ /03_Sep13_2022/target/ /lab7_CalebFontenot/target/ +/MP2_CalebFontenot/target/ diff --git a/MP2_CalebFontenot/pom.xml b/MP2_CalebFontenot/pom.xml new file mode 100644 index 0000000..b39b33b --- /dev/null +++ b/MP2_CalebFontenot/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.calebfontenot.mp2_calebfontenot + MP2_CalebFontenot + 1.0-SNAPSHOT + jar + + UTF-8 + 18 + 18 + com.calebfontenot.mp2_calebfontenot.MP2_CalebFontenot + + \ No newline at end of file diff --git a/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/CheckIBSN_10.java b/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/CheckIBSN_10.java new file mode 100644 index 0000000..67fea17 --- /dev/null +++ b/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/CheckIBSN_10.java @@ -0,0 +1,58 @@ +/* + * 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.mp2_calebfontenot; + +import java.util.*; + +/** + * + * @author caleb + */ +public class CheckIBSN_10 { + public static void main(String[] args) + { + // Create scanner + Scanner input = new Scanner(System.in); + // define vars + int digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8, digit9, inputISBN, outputISBN; + boolean debug = false; + + // Scan individual numbers + System.out.print("Enter the first 9 digits of an ISBN as an integer: "); + inputISBN = input.nextInt(); // Get the first 9 digits of the ISBN + + + // Divide the number up into 9 digits + digit1 = inputISBN / 100000000 % 10; + digit2 = inputISBN / 10000000 % 10; + digit3 = inputISBN / 1000000 % 10; + digit4 = inputISBN / 100000 % 10; + digit5 = inputISBN / 10000 % 10; + digit6 = inputISBN / 1000 % 10; + digit7 = inputISBN / 100 % 10; + digit8 = inputISBN / 10 % 10; + digit9 = inputISBN / 1 % 10; + //System.out.println(digit1 +"" + digit2 +"" + digit3 +"" + digit4 +"" + digit5 +"" + digit1 +"" + ); + //Print digits for debugging + if (debug == true) + { + System.out.println("inputISBN: " + inputISBN); + System.out.println("ISBN split into 9 digits: " + (digit1) + " " + (digit2) + " " + (digit3) + " " + (digit4) + " " + (digit5) + " " + (digit6) + " " + (digit7) + " " + (digit8) + " " + (digit9)); + } + // Calculate! + outputISBN = ((digit1 * 1) + (digit2 * 2) + (digit3 * 3) + (digit4 * 4) + (digit5 * 5) + (digit6 * 6) + (digit7 * 7) + (digit8 * 8) + (digit9 * 9)) % 11; + + + //Output + if (outputISBN == 10) + { + System.out.println("The ISBN-10 number is " + inputISBN + "X"); + } + else + { + System.out.println("The ISBN-10 number is " + inputISBN + outputISBN); + } + } +} diff --git a/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RandomNumber.java b/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RandomNumber.java new file mode 100644 index 0000000..37e998f --- /dev/null +++ b/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RandomNumber.java @@ -0,0 +1,43 @@ +/* + * 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.mp2_calebfontenot; + + +/** + * + * @author caleb + */ +public class RandomNumber { + public static void main(String[] args) + { + // Define vars + int number = (int) (Math.random() * 12) + 1; + System.out.println("Random generated number is " + number); + + //long if else chain + if (number == 1) + System.out.println("Month is January"); + else if (number == 2) + System.out.println("Month is February"); + else if (number == 3) + System.out.println("Month is March"); + else if (number == 4) + System.out.println("Month is April"); + else if (number == 5) + System.out.println("Month is June"); + else if (number == 7) + System.out.println("Month is July"); + else if (number == 8) + System.out.println("Month is August"); + else if (number == 9) + System.out.println("Month is September"); + else if (number == 10) + System.out.println("Month is October"); + else if (number == 11) + System.out.println("Month is November"); + else if (number == 12) + System.out.println("Month is December"); + } +}