My problem area is the Area Calculator , I made it to only calculate fa square. But now I want to add in a Circle(radius * radius * pi) and Triangle(base * height/2)
And my second problem is that, every calculator (Area calculator) has to have the following features:
When a user presses "Y" Area calculator menu must be redrawn
When a user presses "N" Main menu of the calculator program must be redrawn.
Your help will be appreciated, please when replying try not to be too complex because I am a beginner and still trying to adjust to java. Thank you
import java.util.Scanner;
public class Calculator
{
public static void main(String[] args)
{
Scanner keyboard= new Scanner(System.in);
System.out.print("Enter calculator choice: ");
int userChoice = keyboard.nextInt();
int num1 = 0;
int num2 = 0;
String arithmeticOperation = "";
//initialise variables for choices 2 and 3
int length = 0;
int width = 0;
int height = 0;
switch(userChoice)
{
case 1:
System.out.println("Arithmetic Calculator");
break;
case 2:
System.out.println("Area Calculator");
break;
case 3:
System.out.println("Volume Calculator");
break;
}
if(userChoice == 1)
{
System.out.print("Enter first number: ");
num1 = keyboard.nextInt();
System.out.print("Enter second number: ");
num2 = keyboard.nextInt();
System.out.print("Enter Arithmetic Operation: ");
arithmeticOperation = keyboard.next();
System.out.println("Answer = " + arithmeticCalculator(num1, num2, arithmeticOperation));
}
else if(userChoice == 2)
{
System.out.print("Enter Length of the square: ");
length = keyboard.nextInt();
System.out.print("Enter Width of the square: ");
width = keyboard.nextInt();
System.out.println("Area = " + areaCalculator(length, width) + " Units^2");
}
else if(userChoice == 3)
{
System.out.print("Enter Length of the cube: ");
length = keyboard.nextInt();
System.out.print("Enter Width of the cube: ");
width = keyboard.nextInt();
System.out.print("Enter Height of the cube: ");
height = keyboard.nextInt();
System.out.println("Volume = " + volumeCalculator(length, width, height) + " Units^3");
}
else
{
System.out.println("Error, choose a number between 1 and 3 inclusive.");
}
}
public static int arithmeticCalculator(int number1, int number2, String arithmeticOperator)
{
if(arithmeticOperator.equals("+"))
{
return number1 + number2;
}
else if(arithmeticOperator.equals("-"))
{
return number1 - number2;
}
else
{
return 0;
}
}
public static int areaCalculator(int length, int width)
{
return length * width;
}
public static int volumeCalculator(int length, int width, int height)
{
return length * width * height;
}
}
Mod edit - Please

New Topic/Question
Reply



MultiQuote




|