0% found this document useful (0 votes)
37 views2 pages

Java Packages Demo

The document provides a Java code example for a package named 'mycalculator' that contains a class 'Operations' with methods for addition, subtraction, multiplication, and division. It also includes a 'Calculator' class that imports 'Operations' and demonstrates the use of these methods with specific arithmetic operations. The output of each operation is printed to the console.

Uploaded by

zoom temp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Java Packages Demo

The document provides a Java code example for a package named 'mycalculator' that contains a class 'Operations' with methods for addition, subtraction, multiplication, and division. It also includes a 'Calculator' class that imports 'Operations' and demonstrates the use of these methods with specific arithmetic operations. The output of each operation is printed to the console.

Uploaded by

zoom temp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PRACTICE QUESTION

Q1) Create a package with one class containing 4 methods for the 4 operations to do
addition, subtraction, multiplication, division. Import this package and display the result for
the following questions:
i) 3+10
ii) 24-59
iii) 15*25
iv) 24/5

Ans) Code

package mycalculator;
import [Link].*;

public class Operations


{
public void add(int a, int b){
[Link]("The sum is: " + (a+b));
}
public void subtract(int a, int b){
[Link]("The difference is: " + (a-b));
}
public void multiply(int a, int b){
[Link]("The product is: " + (a*b));
}
public void divide(int a, int b){
[Link]("The quotient is: " + (a/b));
}
}
import [Link];

public class Calculator


{
public static void main(String args[]){
Operations obj = new Operations();
[Link](3,10);
[Link](24,59);
[Link](15,25);
[Link](24,5);
}
}

You might also like