From f747666162b860797af7daf02a3c6babe79cf950 Mon Sep 17 00:00:00 2001 From: Lina Date: Sat, 9 Dec 2023 20:16:56 -0800 Subject: [PATCH] Completed Lab006 --- README.md | 2 +- src/Lab006.java | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/Lab006.java diff --git a/README.md b/README.md index ae51dc5..011c39b 100644 --- a/README.md +++ b/README.md @@ -5,7 +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? - +The returned value is ignored but still will be executed. ## PART 2 * Fork and clone this lab as you have done in all previous labs, and then complete the following: * Create a new **class** called **Lab006** diff --git a/src/Lab006.java b/src/Lab006.java new file mode 100644 index 0000000..eb4470d --- /dev/null +++ b/src/Lab006.java @@ -0,0 +1,56 @@ +/* +* +* @author Trevor Hartman +* @author Angelina Perez +* +*/ +import java.util.Scanner; +public class Lab006 { + //two integer instance variables + private int n; + private int m; + + /** + * create a constructor + * @param n + * @param m + */ + + public Lab006(int n, int m) { + this.n = n; + this.m = m; + } + + /** + * + * @return returns true if n is evenly divisible by m, and false otherwise. + */ + + public boolean isDivisible() { + return n % m == 0; + } + + /** + * n a static main method, prompt the user for two integers and store those values into local variables. + * Use the local variables as the arguments to the Lab006 constructor when creating a new Lab006 object. + * Call isDivisible using a Lab006 object, and be sure to have code that "handles" the returned value from isDivisible + * se a print command to display an appropriate label and the result of isDivisible. + * @param args + */ + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Enter first number(n):"); + int n = scanner.nextInt(); + System.out.println("Enter second number(m):"); + int m = scanner.nextInt(); + Lab006 lab = new Lab006(n, m); + if (lab.isDivisible()) { + System.out.printf("%s is divisible by %s.", n, m); + } else { + System.out.printf("%s is not divisible by %s.", n, m); + + + } + } +} \ No newline at end of file