Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the IST Linux Putty system (using the nano editor) create the following Ja

ID: 3878815 • Letter: U

Question

Using the IST Linux Putty system (using the nano editor) create the following Java command line calculator application Lab2. I would just copy Lab1.java using the cp linux copy command - cp Lab1.java Lab2.java Pass in two arguments from the Linux command line when the program starts. For example java Lab2 value1 value2. Replace value1 and value2 with integers like 200 100 - java Lab2 200 100  This will perform four operations on these values: addition, subtraction, multiply & division and print out the results - see the attached example. The two arguments get passed into the main method as a String array in the variable object named args. Remember they get passed in as strings so you need to parse them into integers using the Integer.parseInt(args[0]) before you can treat them as integers.

Create a new file Java class called Calculate.java. This class will contain two static public methods addition() and subtraction() and two non-static public methods multiply() and division(). These methods will accept two integers as input variables and will return an integer result value. Compile it with javac Calculate.java

In Lab2.java if you copied the file from Lab1.java then modify the Lab1 class identifier to be Lab2. Modify the main method to make calls to all the four methods addition(), subtraction(), multiply() and division() and print out the results to the terminal. Remember how you call static and non-static methods are different and you need to review my video and power point presentation. Please include the Java source code printout along with the program running in your pdf upload.

Your application will have two source files Calculate.java and Lab2.java - compile both of them using javac.

To run it use java Lab2 200 100

Joseph root@ist242:/home/Joe0akes# javac Calculate.java root@ist242:/home/Joe0akes# javac Lab2.java root@ist242:/home/Joe0akes# java Lab2 200 100 Addition result: 300 Subtraction result: 100 Multiplication result: 20000 Division result: 2

Explanation / Answer

Lab2.java

public class Lab2 {

public static void main(String[] args) {

int value1 = Integer.parseInt(args[0]);

int value2 = Integer.parseInt(args[1]);

Calculate obj = new Calculate();

System.out.println("Addition result: "+Calculate.addition(value1, value2));

System.out.println("Subtraction result: "+Calculate.subtraction(value1, value2));

System.out.println("Multiplication result: "+obj.multiply(value1, value2));

System.out.println("Division result: "+obj.division(value1, value2));

}

}

Calculate.java

public class Calculate {

public static int addition(int value1, int value2) {

return value1 + value2;

}

public static int subtraction(int value1, int value2) {

return value1 - value2;

}

public int multiply(int value1, int value2) {

return value1 * value2;

}

public int division(int value1, int value2) {

return value1 / value2;

}

}

Output:

Addition result: 300
Subtraction result: 100
Multiplication result: 20000
Division result: 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote