From 52fd4fcb79a7a7a70df7d6b5b8f2323f02ed34b9 Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 7 Oct 2023 16:34:04 -0700 Subject: [PATCH] lab 6 done --- .idea/misc.xml | 2 +- README.md | 1 + src/.gitkeep | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/Lab006.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/Lab006.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 7464918..ef1ccd0 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/README.md b/README.md index ae51dc5..8f17824 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ In this README.md, answer the following question: * What happens if you invoke a value method (i.e. a method that returns a result) and don't do anything with the returned result; that is, if you don't assign the returned result to a variable or use it as part of a larger expression? +* When you invoke a method that returns a value and don't do anything with the returned result, the result is discarded ## PART 2 * Fork and clone this lab as you have done in all previous labs, and then complete the following: diff --git a/src/.gitkeep b/src/.gitkeep index e69de29..f92d8da 100644 --- a/src/.gitkeep +++ b/src/.gitkeep @@ -0,0 +1,47 @@ +/** + * @author Taylor Christie + * @date 10/5/2023 + */ + +import java.util.Scanner; +public class Lab006 { + private int n; + private int m; + + /** + * Lab006 Constructor + * @param user1 First integer inputted by user + * @param user2 Second integer inputted by user + */ + public Lab006(int user1, int user2) { + this.n = user1; + this.m = user2; + } + + /** + * Takes the inputted integers and checks if they're evenly divisible + * @return true or false + */ + public boolean isDivisible() { + if (n % m == 0) { + return true; + } else { + return false; + } + } + + /** + * Prompts user for integers and calls the isDivisible method + * @param args + */ + public static void main (String[] args) { + Scanner scan = new Scanner(System.in); + System.out.println("Type in your first integer: "); + int user1 = scan.nextInt(); + System.out.println("Type in the number you wish to divide the first integer by: "); + int user2 = scan.nextInt(); + Lab006 name = new Lab006(user1, user2); + boolean divisible = name.isDivisible(); + System.out.println("The integers were evenly divisible - " + divisible); + } +} \ No newline at end of file diff --git a/src/Lab006.java b/src/Lab006.java new file mode 100644 index 0000000..5c5c58a --- /dev/null +++ b/src/Lab006.java @@ -0,0 +1,44 @@ +import java.util.Scanner; + + public class Lab006 { + + int n; + + int m; + + + // n The first integer value. + // m The second integer value. + + public Lab006(int n, int m) { + this.n = n; + this.m = m; + } + + // check if n is divisable by m + + public boolean isDivisble() { + return (n % m) == 0; + + } + + // main method which handles getting the user input and displaying the result + public static void main(String[] args) { + int number1; + int number2; + Scanner scan = new Scanner(System.in); + System.out.println("Enter the integer: "); + number1 = scan.nextInt(); + System.out.println("Enter the integer: "); + number2 = scan.nextInt(); + Lab006 labObject = new Lab006(number1, number2); + + boolean result = labObject.isDivisble(); + if (result) { + System.out.println(number1 + " is evenly divisible by " + number2); + } else { + System.out.println(number1 + " is not evenly divisible by " + number2); + } + + } + }