Question

In: Computer Science

create calculator standard using java language with OOP rule and interfaces.

create calculator standard using java language with OOP rule and interfaces.

Solutions

Expert Solution

note:create interface,class,and main class separate window

//create interface of same package

//============interface====================//

package calculator;
public interface NewInterface {
/** a+b */
public double add(double a, double b);

/** a-b */
public double subtract(double a, double b);

/** a*b */
public double multiply(double a, double b);

/** a/b */
public double division(double a, double b);

}

//---------interface end=================//

//create a class of same package===========

//========class calsi begain============
package calculator;
public class calsi implements NewInterface{

@Override
public double add(double a, double b) {

return a + b;
}

@Override
public double subtract(double a, double b) {

return a - b;
}

@Override
public double multiply(double a, double b) {
return a * b;
}

@Override
public double division(double a, double b) {

double temp=0.0;
try{
temp= a/b;}
catch(Exception e)
{
System.out.println(e);
}
return temp;
}
}
//========class calsi end============

//======main class===========

package calculator;
import java.util.Scanner;
/**
*
* @author Student
*/
public class Calculator {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
calsi cal=new calsi();
double a,b;
while(true){

System.out.println("Enter value a");
a=sc.nextDouble();
System.out.println("Enter operation (+ - * /)");
String operator=sc.next();
System.out.println("Enter value b");
b=sc.nextDouble();
switch(operator){
  
case "+":System.out.println("="+cal.add(a,b));break;
case "-": System.out.println("="+cal.subtract(a, b));break;
case "*":System.out.println("="+cal.multiply(a, b));break;
case "/":System.out.println("="+cal.division(a, b));break;
default:
System.out.println("who have not choosen any operator");
  
}
  
System.out.println("1 to continue and 0 to quit");
int y=sc.nextInt();
if(y==0)break;
  
}

}
  
}
//=====main class end==

//=============output===================

run:
Enter value a

3.5
Enter operation (+ - * /)
*
Enter value b
5.5
----------------------------
=19.25
----------------------------
1 to continue and 0 to quit
0
BUILD SUCCESSFUL (total time: 27 seconds)


Related Solutions

create scientific calculator using java language with OOP rule and interfaces.
create scientific calculator using java language with OOP rule and interfaces.
Please use Java language in an easy way with comments! Thanks! Create a calculator that uses...
Please use Java language in an easy way with comments! Thanks! Create a calculator that uses an array of buttons for numbers from 0-9, the . for decimals, and for operators +, -, * ,/ and = as well as a JTextfield that displays the current value or the result. Use ActionListeners and LayoutManagers appropriately. The example below shows how to determine which button has been clicked. ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand()); }...
Language: Java(Netbeans) Implement a simple calculator.
Language: Java(Netbeans) Implement a simple calculator.
Please code the following, using the language java! Build a simple calculator that ignores order of...
Please code the following, using the language java! Build a simple calculator that ignores order of operations. This “infix” calculator will read in a String from the user and calculate the results of that String from left to right. Consider the following left-to-right calculations: "4 + 4 / 2" "Answer is 4" //not 6, since the addition occurs first when reading from left to right “1 * -3 + 6 / 3” “Answer is 1” //and not -1Start by copying...
Create a calculator in java without using the math library which converts an integer into a...
Create a calculator in java without using the math library which converts an integer into a hexadecimal number.
Create a Scorekeeper app in android studio by using java language - Layouts | Widgets Create...
Create a Scorekeeper app in android studio by using java language - Layouts | Widgets Create the layout for your score keeping app. The app should have: Two team names (TextViews) Two scores (TextViews) Buttons to increase/ decrease the scores An amount to change the score by (RadioButtons) You must have at least two score options The scores can be changed by anything you want American football: 1, 2, 3, 6 Basketball: 1, 2, 3 Freestyle wrestling: 1, 2, 3,...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to input two numbers using scanner class Print the instruction of the menu for the calculator program Ask user to press 0 to Quit Ask user to press 1 to Add Ask user to press 2 to Substract Ask user to press 3 to Multiply Ask user to press 4 to Divide Perform correct calcuation based on user inputs and print the result Print error...
Using the Java programming language: Create and implement a class Car that models a car. A...
Using the Java programming language: Create and implement a class Car that models a car. A Car is invented to have a gasoline tank that can hold a constant max of 12.5 gallons, and an odometer that is set to 0 for a new car. All cars have an original fuel economy of 23.4 miles per gallon, but the value is not constant. Provide methods for constructing an instance of a Car (one should be zero parameter, and the other...
Creat a theater booking system in java language using : 1.OOP objects -Classes 2.encapsulation 3.polymorphism 4.inheritance...
Creat a theater booking system in java language using : 1.OOP objects -Classes 2.encapsulation 3.polymorphism 4.inheritance 5.abstract class
using C language Create a bitwise calculator that ask user for input two input, first int,...
using C language Create a bitwise calculator that ask user for input two input, first int, bitwise operation, second int (i.e 5 & 9) only those bitwise operation are allowed: & ~ ^ | << >>. If user uses wrong operators stop program and ask again. Convert the first int and second int into 8 BITS binary (00000000) and use bitwise operator given by user to either AND, OR, XOR, etc (ie 1001 & 1111)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT