Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 44 additions & 0 deletions src/Lab006.java
Original file line number Diff line number Diff line change
@@ -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 + ".");
}
}
}