Java #46: How To perform Math Calculations between Classes

———–Output—————

————Full Source Code————-

//Programmer: Akinwale Owi
//Company: Dagba Computers
//Program Purpose: Perform Math Calculations between Classes

package dagbacomputers;

/**
*
* @author Akin
*/

public class DagbaComputers {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
//Testing
System.out.printf(“Testing” + “\n”);

//Creating a calc object
calc calculator = new calc();

//Creating the variable we will add
int test = 33;

//Printing the test variable
System.out.printf(“Original Value of test:” + test + “\n”);

//Variable that will hold it’s value after addition
int testAdd = calculator.adding(test);

//Printing testAdd to see if it worked
System.out.printf(“Value after going to adding method: ” + testAdd + “\n”);

//—————Multiplying——————–

//Creating an object for the multiply class
multiply doubling = new multiply();

//Variable that will hold testAdd’s value after multiplication
int doubleAdd = doubling.doubleIT(testAdd);

//Printing to test
System.out.println(“Value after going to doubleIT: ” + doubleAdd);

}//End of Main

}//End of DagbaComputers Class

//calc class
class calc
{
//Constructor
calc()
{
//Header
System.out.printf(“————Math Calculations———” + “\n”);
//Space
System.out.printf(“\n”);
}
//End of Constructor

//Add function
int adding(int x)
{
//Adding 600 to x value
int y = x + 600;

//returning new value to the main
return y;

}//End of adding function

}//end of calc class

//multiply class
class multiply
{
//Constructor
multiply(){}

//
int doubleIT(int g)
{
//Taking in the value and multiplying it by 2
int w = g * 2;
//Value that the function returns
return w;
}//End of doubleIT
}//end of multiply class

————–End of Program————

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: