diff --git a/.idea/misc.xml b/.idea/misc.xml index 7464918..4dd49c4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,5 @@ - - + \ No newline at end of file diff --git a/README.md b/README.md index ae51dc5..c368ce6 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? +* it doesn't get used and just gets discarded but can cause error in the code ## PART 2 * Fork and clone this lab as you have done in all previous labs, and then complete the following: diff --git a/src/Lab006.java b/src/Lab006.java new file mode 100644 index 0000000..b5455c2 --- /dev/null +++ b/src/Lab006.java @@ -0,0 +1,44 @@ +import java.util.Scanner; + +/** + * @author Olivia McKittrick + * class 006 uses two integer instance variables n & m + * then it checks if n is divisible by m + * asks the user to enter a variable and prints whether n is divisisble by m + */ +public class Lab006 { + private final int n; // integer instance 1 + private final int m; // integer instance 2 + + public Lab006(int n, int m) { // Constructor that takes two integers as parameters + this.n = n; // Assigning value n parameter to n instance variable + this.m = m; // Assigning value m parameter to m instance variable + } + + public boolean isDivisible() { // Method that checks if n is evenly divisible by m + if (m == 0) { + return false; + } + return n % m == 0; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.print("Enter the first integer (n): "); // Prompt the user for integer 1 + int userN = scanner.nextInt(); // Storing in local variable + + System.out.print("Enter the second integer (m): "); // Prompt the user for integer 2 + int userM = scanner.nextInt(); // Storing in local variable + + Lab006 labObject = new Lab006(userN, userM); // Created lab object with user values + + boolean result = labObject.isDivisible(); // Uses isDivisible with labObject + + if (result) { + System.out.println(userN + " is evenly divisible by " + userM + "."); + } else { + System.out.println(userN + " is not evenly divisible by " + userM + "."); + } + } +}