Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.145.108.43
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/zwang/cs202/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/zwang/cs202/Calculator.java
//
//	File: Calculator.java
//
//	Test II: #5
//

import java.util.Scanner;

public class Calculator
{
	private double v1;
	private double v2;
	public Calculator(double a, double b)
	{
		v1 = a;
		v2 = b;
	}
	public double Add()
	{
		return v1 + v2;
	}
	public double Sub()
	{
		return v1 - v2;
	}
	public double Mul()
	{
		return v1 * v2;
	}
	public double Div()
	{
		return v1 / v2;
	}
	public String toString()
	{	String a = v1 + " + " + v2 + " = " + Add() + "\n";
		String s = v1 + " - " + v2 + " = " + Sub() + "\n";
		String m = v1 + " * " + v2 + " = " + Mul() + "\n";
		String d = v1 + " / " + v2 + " = " + Div() + "\n";

		return a + s + m + d;
	}
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		System.out.print("Input two operands: ");
		double x = sc.nextDouble();
		double y = sc.nextDouble();

		Calculator cal = new Calculator(x, y);
		System.out.println("\n\n" + cal);


		System.out.println("\n\nDone.\n\n");
	}
}






Stv3n404 - 2023