Alternatively, you can also get these program files using the command:
cp /home/cheung/teaching/web/170/Projects/hw4/Handouts/*.java ~/cs170/hw4
In the remainder of the homework description, I will assume that you have saved these file in your ~/cs170/hw4 directory.
I believe that you have work enough with BlueJ to turn Non-BlueJ Java projects into a BlueJ one.
Look at the test program LCMTest.java :
public class LCMTest { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a, b; int ans; System.out.print("Enter a: "); a = in.nextInt(); System.out.print("Enter b: "); b = in.nextInt(); LCM x = new LCM(a, b); System.out.println("The LCM of " + a + " and " + b + " is " + x.findLCM()); } } |
The test program LCMTest.java first reads in 2 integer numbers a and b. Then it construct an LCM object x and invokes the findLCM() method.
The constructor LCM(a, b) must accepts 2 integers (a and b) and construct an LCM object.
The method findLCM() does not take any parameter; and returns the Least Common Multiple (LCM) of the numbers a and b that was previously used to construct the LCM object.
Do NOT change the test program
You must write the LCM class in the LCM.java file.
You must provide the necessary methods in the LCM class so that the test program LCMTest.java will compile and run to find the Least Common Multiple of the numbers a and b.
n / a has a remainder 0AND
n / b has a remainder 0
Edit the program file LCM.java in your ~/cs170/hw4 directory.
Your task is to write the following methods in the LCM.java file:
The construct must copy the integer parameters into the instance variables (for longer term storage)
(In other words: method findLCM() must compute and return the Least Common Multiple of a and b
Use these facts to help you formulate the search strategy:
Test 1: ======= Enter a: 12 Enter b: 39 The LCM of 12 and 39 is 156 Test 2: ======= Enter a: 24 Enter b: 56 The LCM of 24 and 56 is 168
/home/cs170001/turnin ~/cs170/hw4/LCM.java hw4