Skip to content

Instantly share code, notes, and snippets.

@DeshayQ
Created January 6, 2017 20:54
Show Gist options
  • Save DeshayQ/671c00a0e489118040a9b599ed8f3146 to your computer and use it in GitHub Desktop.
Save DeshayQ/671c00a0e489118040a9b599ed8f3146 to your computer and use it in GitHub Desktop.
Code for CalcMain Program
package calcmain;
/**
*
* @author deshay.cunningham
*/
import java.util.Scanner;
public class CalcMain {
/**
* @param args the command line arguments
*/
static double getAddition(double x, double y) {
return x+y;
}
static double getSubtraction(double x, double y) {
return x-y;
}
static double getMultiplication(double x, double y) {
return x*y;
}
static double getDivision(double x, double y) {
return x/y;
}
public static void main(String[] args) {
int op, n, a;
double x=0, y=0, z=0;
System.out.println ("Welcome to CSC 159 Calculator.");
System.out.println("******************************");
System.out.println("Choose from any operation below");
System.out.println("1 for ADDITION");
System.out.println("2 for SUBTRACTION");
System.out.println("3 for MULTIPLICATION");
System.out.println("4 for DIVISION");
System.out.println("5 for Temperature Converter from F to C");
System.out.println("6 for Temperature Converter from C to F");
System.out.println("7 for Convert miles to kilometers");
System.out.println("8 for Convert kilometers to Miles");
System.out.print("Please enter your choice based on the above menu:");
Scanner Keyin = new Scanner(System.in); //define Keyin object of type Scanner for all integer readings
op=Keyin.nextInt();
while(op > 8)
{
System.out.print("Please enter your choice based on the above menu:");
op=Keyin.nextInt();
}
if(op < 5)
{
System.out.print("Input first operand: ");
x = Keyin.nextInt();
System.out.print("Input second operand: ");
y = Keyin.nextInt();
}
if(op == 1)
{
z=getAddition(x, y);
System.out.println("The result of adding " + x + " and "+ y +" is " + z);
}
if(op == 2)
{
z=getSubtraction(x,y);
System.out.println("The result of subtracting " + x + " and "+ y +" is " + z);
}
if(op == 3)
{
z=getMultiplication(x, y);
System.out.println("The result of multiplying " + x + " and "+ y +" is " + z);
}
if(op == 4)
{
if(y != 0)
{
z=getDivision(x,y);
System.out.println("The result of dividing " + x + " and "+ y +" is " + z);
}
else
{
System.out.println("The result is infinity.");
}
}
if(op == 5)
{
System.out.print("Please enter the temperature in degrees Fahrenheit: ");
//x=System.in.read();
//z = FtoC(x);
System.out.println("The calculated temperature in degree Celsius is " + z);
}
if(op == 6)
{
System.out.print("Please enter the temperature in degrees Celcius: ");
// x=Keyin.nextInt();
//z = CtoF(x);
System.out.println("The calculated temperature in degree Fahrenheit is " + z);
}
if(op == 7)
{
System.out.print("Please enter the miles to convert to kilometers: ");
//x=Keyin.nextInt();
//z = MtoK(x);
System.out.println("The miles to kilometer conversion is " + z);
}
if(op == 8)
{
System.out.print("Please enter the Kilometers to convert to Miles: ");
//x=Keyin.nextInt();
//z = KtoM(x);
System.out.println("The Kilometers to Miles conversion is " + z);
}​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment