Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Java application Run configuration will contain two program arguments to be passed in. These two arguments will be passed in when the program starts

The Java application Run configuration will contain two program arguments to be passed in. These two arguments will be passed in when the program starts - for example, integers like 5 and 10. This application will perform four operations on these two values: addition, subtraction, multiply & division and it will print out the results. 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 Calculate will contain two static public methods addition() and subtraction() which you call in the Main class using the Calculate class name. The Calculate class will also contain two non-static public methods multiply() and division() which you call using the Calculate object that you create. All these methods will accept two integers as input arguments and will return an integer result value.

Remember to call static methods just use the className.methodName() for example Calculate.addition(). To call non-static methods, you will need to first instantiate an object of that class then call the method using the object objectName.methodName() for example calc.addition() using the calc object you created first from the Calculate class.

Modify the main method in Lab7 to make calls to all four of the Calculate class 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. There should be only two classes in this IntelliJ solution Calculate and Main as shown below. To create a new Class just right click on your package (edu.psu.ist242) select New -> Java Class -> Calculate.

The output should look like this

image text in transcribed

Running Example using Program Arguments 5 10 Run + + Main /Library/Java/JavaVirtual Machines/jdk1.7. objc(1666]: Class JavaLaunchHelper is imp Addition result: 15 Subtraction result: -5 Multiplication result: 50 Division result: 0 L

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students also viewed these Databases questions