0% found this document useful (0 votes)
53 views

Java Calculator

This document contains code for a basic calculator program written in Java. It defines classes for addition, subtraction, multiplication and division that each perform an operation on input numbers. The main method gets user input for three numbers and creates objects to call the methods for each operation class. These calculate and output the result and whether it is even or odd for addition. The code includes screenshots and the full Java code listing.

Uploaded by

NONO P STUART
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)
53 views

Java Calculator

This document contains code for a basic calculator program written in Java. It defines classes for addition, subtraction, multiplication and division that each perform an operation on input numbers. The main method gets user input for three numbers and creates objects to call the methods for each operation class. These calculate and output the result and whether it is even or odd for addition. The code includes screenshots and the full Java code listing.

Uploaded by

NONO P STUART
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
You are on page 1/ 8

AGABA EBONS 2020/BIT/161/PS

MBARARA UNIVERSITY OF SCIENCE AND TECHNOLOGY

FACULTY OF COMPUTING AND INFORMATICS

DEPARTMENT OF INFORMATION TECHNOLOGY

NAME: AGABA EBONS

REG NUMBER: 2020/BIT/161/Ps


AGABA EBONS 2020/BIT/161/PS

MY SCREEN SHOTS
AGABA EBONS 2020/BIT/161/PS
AGABA EBONS 2020/BIT/161/PS

THE ENTIRE CODE

package calc;

import java.util.Scanner;

public class Calc{

public static int a;

public static int b;

public static int d;

public static int k;

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter first number:");


AGABA EBONS 2020/BIT/161/PS

a = scan.nextInt();

System.out.println("Enter second number:");

b = scan.nextInt();

System.out.println("Enter third number:");

d = scan.nextInt();

Calc math=new Calc();

Calc.Addition one =math.new Addition();

one.add2();

one.add();

Calc.Subtraction two = math.new Subtraction();

two.subtract2();

two.subtract();

Calc.Multiplication three = math.new Multiplication();

three.multiply2();

three.multiply();

Calc.Division four = math.new Division();

four.divide2();

four.divide();

class Addition{

int c =a+b+d;

public int add(){


AGABA EBONS 2020/BIT/161/PS

System.out.println("Addition="+c);

Addition valu=new Addition();

Addition.validator value= valu.new validator();

value.validate();

return 0;

public void add2(){

System.out.println("**THE ADDITION MENU**");

class validator{

int w=c%2;

public int validate(){

k = w;

switch(k){

case 1 -> System.out.println("not known");

case 2 -> System.out.println("the sum is an even number");

default -> System.out.println("the sum is an even number");

return 0;}

}}

class Subtraction{

public int subtract(){

int c = a-b-d;
AGABA EBONS 2020/BIT/161/PS

System.out.println("subtraction="+c);

return 0;

public void subtract2(){

System.out.println("**THE SUBTRACTION MENU**");

class Multiplication{

public int multiply(){

int c = a*b*d;

System.out.println("Multiplication="+c);

return 0;

public void multiply2(){

System.out.println("**THE MULTIPLICATION MENU**");

} class Division{

public int divide(){

float f = a/b/d;

System.out.println("Division="+f);

return 0;

public void divide2(){

System.out.println("**THE DIVISION MENU**");

}
AGABA EBONS 2020/BIT/161/PS

You might also like