Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import static java.lang.System.*;
- public class main
- {
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- int choice = 0;
- double fAnswer;
- String quadAns;
- boolean choice1;
- while(choice != 4)
- {
- choice1 = false;
- out.println("\n+-------------------------------------+\n");
- out.println("\t1) Quadratic Calculator");
- out.println("\t2) Area Calculator");
- out.println("\t3) Volume Calculator");
- out.println("\t4) Exit");
- choice = keyboard.nextInt();
- if (choice == 1)
- {
- double [] a;
- a = quadCal();
- out.println("The answer is: " + a[1] + " " + a[2]);
- choice1 = true;
- }
- else if (choice == 2)
- {
- fAnswer = areaCal();
- }
- else if(choice == 3)
- {
- fAnswer = volCal();
- }
- else if(choice == 4)
- {
- System.exit(0);
- }
- else
- {
- out.println("Error");
- choice1 = true;
- }
- if (choice1 == false) {
- out.println("The answer is: " + fAnswer);
- }
- else
- {
- }
- }
- }
- public static double[] quadCal()
- {
- Scanner keyboard = new Scanner(System.in);
- double[] quad;
- quad = new double[2];
- double a, b, c, n = 0;
- out.print("Enter the value of a: ");
- a = keyboard.nextDouble();
- out.println();
- out.print("Enter the value of b: ");
- b = keyboard.nextDouble();
- out.println();
- out.print("Enter the value of c: ");
- c = keyboard.nextDouble();
- out.println();
- quad[0] = ((b*(1-2)) + Math.sqrt((b*b) - (4*a*c)))/(2*a);
- quad[1] = ((b*(1-2)) - Math.sqrt((b*b) - (4*a*c)))/(2*a);
- return quad;
- }
- public static double areaCal()
- {
- Scanner keyboard = new Scanner(System.in);
- double a, b, area;
- out.print("Enter the value of height: ");
- a = keyboard.nextDouble();
- out.println();
- out.print("Enter the value of length: ");
- b = keyboard.nextDouble();
- out.println();
- area = a * b;
- return area;
- }
- public static double volCal()
- {
- Scanner keyboard = new Scanner(System.in);
- double a, b, c, volume;
- out.print("Enter the value of height: ");
- a = keyboard.nextDouble();
- out.println();
- out.print("Enter the value of length: ");
- b = keyboard.nextDouble();
- out.println();
- out.print("Enter the value of depth: ");
- c = keyboard.nextDouble();
- out.println();
- volume = a * b * c;
- return volume;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement