Adm1n_0v3rride

Calculator.java

Jul 29th, 2021
1,070
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package calculator;
  7.  
  8. /**
  9.  * Calculator v1.0
  10.  * @author Matthew M. Ciapha
  11.  */
  12.  
  13. import javax.swing.*;
  14. import javax.swing.JOptionPane;
  15. import java.awt.*;
  16. import java.awt.event.*;
  17. import javax.swing.*;
  18. import java.awt.Desktop;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import java.net.URI;
  22. import java.util.*;
  23. import java.text.*;
  24.  
  25. public class Calculator {
  26.  
  27.     /**
  28.      * @param args the command line arguments
  29.      */
  30.    
  31.     public static void Division() {
  32.        
  33.         int firstdivisionnumber;
  34.         int seconddivisionnumber;
  35.         Scanner calculatordivisonfirstsection = new Scanner(System.in);
  36.        
  37.         System.out.println("\n");
  38.        
  39.         System.out.println("Enter The First Number:>>\t");
  40.         firstdivisionnumber = calculatordivisonfirstsection.nextInt();
  41.        
  42.         System.out.println("Enter The Second Number:>>\t");
  43.         seconddivisionnumber = calculatordivisonfirstsection.nextInt();
  44.        
  45.         int answerdivisononeortwice = firstdivisionnumber / seconddivisionnumber;
  46.         System.out.println("\n");
  47.         System.out.format("Answer:>>\t%d", answerdivisononeortwice);
  48.         System.out.println("\n");
  49.        
  50.     }
  51.    
  52.     public static void Addition() {
  53.        
  54.         int firstadditionnumber;
  55.         int secondadditionnumber;
  56.         Scanner calculatoradditionfirstsection = new Scanner(System.in);
  57.        
  58.         System.out.println("\n");
  59.        
  60.         System.out.println("Enter The First Number:>>\t");
  61.         firstadditionnumber = calculatoradditionfirstsection.nextInt();
  62.        
  63.         System.out.println("Enter The Second Number:>>\t");
  64.         secondadditionnumber = calculatoradditionfirstsection.nextInt();
  65.        
  66.         int answeradditiononeortwice = firstadditionnumber + secondadditionnumber;
  67.         System.out.println("\n");
  68.         System.out.format("Answer:>>\t%d", answeradditiononeortwice);
  69.         System.out.println("\n");
  70.        
  71.     }
  72.    
  73.     public static void Subtraction() {
  74.        
  75.         int firstsubtractionnumber;
  76.         int secondsubtractionnumber;
  77.         Scanner calculatorsubtractionfirstsection = new Scanner(System.in);
  78.        
  79.         System.out.println("\n");
  80.        
  81.         System.out.println("Enter The First Number:>>\t");
  82.         firstsubtractionnumber = calculatorsubtractionfirstsection.nextInt();
  83.        
  84.         System.out.println("Enter The Second Number:>>\t");
  85.         secondsubtractionnumber = calculatorsubtractionfirstsection.nextInt();
  86.        
  87.         int answersubtractiononeortwice = firstsubtractionnumber - secondsubtractionnumber;
  88.         System.out.println("\n");
  89.         System.out.format("Answer:>>\t%d", answersubtractiononeortwice);
  90.         System.out.println("\n");
  91.        
  92.     }
  93.    
  94.     public static void Floor_Divison() {
  95.        
  96.         int firstfloordivisonnumber;
  97.         int secondfloordivisonnumber;
  98.         Scanner calculatorfloordivisonfirstsection = new Scanner(System.in);
  99.        
  100.         System.out.println("\n");
  101.        
  102.         System.out.println("Enter The First Number:>>\t");
  103.         firstfloordivisonnumber = calculatorfloordivisonfirstsection.nextInt();
  104.        
  105.         System.out.println("Enter The Second Number:>>\t");
  106.         secondfloordivisonnumber = calculatorfloordivisonfirstsection.nextInt();
  107.        
  108.         int answerfloordivisononeortwice = firstfloordivisonnumber % secondfloordivisonnumber;
  109.         System.out.println("\n");
  110.         System.out.format("Answer:>>\t%d", answerfloordivisononeortwice);
  111.         System.out.println("\n");
  112.        
  113.     }
  114.    
  115.     public static void Multiplication() {
  116.        
  117.         int firstmultiplicationnumber;
  118.         int secondmultiplicationnumber;
  119.         Scanner calculatormultiplicationfirstsection = new Scanner(System.in);
  120.        
  121.         System.out.println("\n");
  122.        
  123.         System.out.println("Enter The First Number:>>\t");
  124.         firstmultiplicationnumber = calculatormultiplicationfirstsection.nextInt();
  125.        
  126.         System.out.println("Enter The Second Number:>>\t");
  127.         secondmultiplicationnumber = calculatormultiplicationfirstsection.nextInt();
  128.        
  129.         int answermultiplicationoneortwice = firstmultiplicationnumber * secondmultiplicationnumber;
  130.         System.out.println("\n");
  131.         System.out.format("Answer:>>\t%d", answermultiplicationoneortwice);
  132.         System.out.println("\n");
  133.        
  134.     }
  135.    
  136.     public static void CircleArea() {
  137.        
  138.         int circleareafirstselectionchoice;
  139.        
  140.         Scanner calculatorformulasonechoice = new Scanner(System.in);
  141.        
  142.         System.out.println();
  143.        
  144.         System.out.println("Welcome To The Circle Area Calculator\n");
  145.        
  146.         System.out.println("Please Select an option\n");
  147.        
  148.         System.out.println("[1] Radius\n");
  149.        
  150.         System.out.println("[2] Perimeter\n");
  151.        
  152.         System.out.println("Choice>>\t");
  153.         circleareafirstselectionchoice = calculatorformulasonechoice.nextInt();
  154.        
  155.         if (circleareafirstselectionchoice == 1) {
  156.            
  157.             int firstcircleareanumber;
  158.             int radiuscircleareaexponent = 2;
  159.            
  160.             Scanner radiusnumberinputsystemchoiceone = new Scanner(System.in);
  161.            
  162.             System.out.println("\n");
  163.            
  164.             System.out.println("Enter The First Number:>>\t");
  165.             firstcircleareanumber = radiusnumberinputsystemchoiceone.nextInt();
  166.            
  167.             int areacirclechoices = (int) (Math.PI * (int) Math.pow(firstcircleareanumber, radiuscircleareaexponent));
  168.             System.out.println("\n");
  169.             System.out.format("Answer:>>\t%d", areacirclechoices);
  170.             System.out.println("\n");
  171.                
  172.         }
  173.        
  174.         else if (circleareafirstselectionchoice == 2) {
  175.            
  176.             int firstcircleperimeternumber;
  177.            
  178.             Scanner perimeterradiusnumberinputsystemchoiceone = new Scanner(System.in);
  179.            
  180.             System.out.println("\n");
  181.            
  182.             System.out.println("Enter The First Number:>>\t");
  183.             firstcircleperimeternumber = perimeterradiusnumberinputsystemchoiceone.nextInt();
  184.            
  185.             int perimetercirclechoices = (int) (2 * Math.PI * firstcircleperimeternumber);
  186.             System.out.println("\n");
  187.             System.out.format("Answer:>>\t%d", perimetercirclechoices);
  188.             System.out.println("\n");
  189.            
  190.     }
  191.        
  192. }
  193.    
  194.     public static void SphereArea() {
  195.        
  196.         int radiusfirstnumber;
  197.         int radiussecondnumber = 2;
  198.         Scanner radiusscanneronechoice = new Scanner(System.in);
  199.        
  200.         System.out.println("\n");
  201.        
  202.         System.out.println("Enter The First Number:>>\t");
  203.         radiusfirstnumber = radiusscanneronechoice.nextInt();
  204.        
  205.         int radiusnumberonesoherechoice = (int) (4 * Math.PI * (int) Math.pow(radiusfirstnumber, radiussecondnumber));
  206.         System.out.println("\n");
  207.         System.out.format("Answer:>>\t%d", radiusnumberonesoherechoice);
  208.         System.out.println("\n");
  209.        
  210.     }
  211.    
  212.     public static void SquareArea() {
  213.  
  214.             int lengthsquareonechoice;
  215.             int lengthofslideonechoice = 2;
  216.  
  217.             Scanner squarelengthinput = new Scanner(System.in);
  218.  
  219.             System.out.println("\n");
  220.  
  221.             System.out.println("Enter The First Number:>>\t");
  222.             lengthsquareonechoice = squarelengthinput.nextInt();
  223.  
  224.             int squarelengthaddedonechoice = (int) Math.pow(lengthsquareonechoice, lengthofslideonechoice);
  225.             System.out.println("\n");
  226.             System.out.format("Answer:>>\t%d", squarelengthaddedonechoice);
  227.             System.out.println("\n");
  228.  
  229.     }
  230.    
  231.     public static void RhombusArea() {
  232.  
  233.             int largediagonalonechoicenumber; // large Diagonal
  234.             int smalldiagonalonechoicenumber; // Small Diagonal
  235.             Scanner rhombusonenumberfirstchoice = new Scanner(System.in);
  236.  
  237.             System.out.println("\n");
  238.  
  239.             System.out.println("Enter The Large Diagonal Number:>>\t");
  240.             largediagonalonechoicenumber = rhombusonenumberfirstchoice.nextInt();
  241.  
  242.             System.out.println("Enter The Small Diagonal Number:>>\t");
  243.             smalldiagonalonechoicenumber = rhombusonenumberfirstchoice.nextInt();
  244.  
  245.             int rhombusonenumberanswerchoice = largediagonalonechoicenumber * smalldiagonalonechoicenumber / 2;
  246.             System.out.println("\n");
  247.             System.out.format("Answer:>>\t%d", rhombusonenumberanswerchoice);
  248.             System.out.println("\n");
  249.  
  250.     }
  251.    
  252.     public static void TriangleArea() {
  253.  
  254.             int baseonechoicenumber; // Base
  255.             int heightdiagonalonechoicenumber; // Height
  256.             Scanner trianglebaseandheightnumber = new Scanner(System.in);
  257.  
  258.             System.out.println("\n");
  259.  
  260.             System.out.println("Enter The Base Number:>>\t");
  261.             baseonechoicenumber = trianglebaseandheightnumber.nextInt();
  262.  
  263.             System.out.println("Enter The Height Number:>>\t");
  264.             heightdiagonalonechoicenumber = trianglebaseandheightnumber.nextInt();
  265.  
  266.             int trianglebaseandheightchoice = baseonechoicenumber * heightdiagonalonechoicenumber / 2;
  267.             System.out.println("\n");
  268.             System.out.format("Answer:>>\t%d", trianglebaseandheightchoice);
  269.             System.out.println("\n");
  270.  
  271.     }
  272.    
  273.     public static void TrapezoidArea() {
  274.  
  275.             int largesidenumber; // large side
  276.             int smallsidenumber; // small side
  277.             int heightnumber; // height
  278.  
  279.             Scanner trapezoidareachoiceone = new Scanner(System.in);
  280.  
  281.             System.out.println("\n");
  282.  
  283.             System.out.println("Enter The Large Side Number:>>\t");
  284.             largesidenumber = trapezoidareachoiceone.nextInt();
  285.  
  286.             System.out.println("Enter The Small Side Number:>>\t");
  287.             smallsidenumber = trapezoidareachoiceone.nextInt();
  288.  
  289.             System.out.println("Enter The Height Number:>>\t");
  290.             heightnumber = trapezoidareachoiceone.nextInt();
  291.  
  292.             int trapezoidanswerchoice = (largesidenumber + smallsidenumber) * heightnumber / 2;
  293.             System.out.println("\n");
  294.             System.out.format("Answer:>>\t%d", trapezoidanswerchoice);
  295.             System.out.println("\n");
  296.            
  297.     }
  298.    
  299.     public static void RectangleArea() {
  300.  
  301.             int widthlengthnumber; // width
  302.             int heightlengthnumber; // height
  303.  
  304.             Scanner rectangleareachoiceone = new Scanner(System.in);
  305.  
  306.             System.out.println("\n");
  307.  
  308.             System.out.println("Enter The Width Number:>>\t");
  309.             widthlengthnumber = rectangleareachoiceone.nextInt();
  310.  
  311.             System.out.println("Enter The Height Number:>>\t");
  312.             heightlengthnumber = rectangleareachoiceone.nextInt();
  313.  
  314.             int rectangleanswerchoice = widthlengthnumber * heightlengthnumber;
  315.             System.out.println("\n");
  316.             System.out.format("Answer:>>\t%d", rectangleanswerchoice);
  317.             System.out.println("\n");
  318.  
  319.     }
  320.    
  321.     public static void CubeVolumes() {
  322.        
  323.         int sidelength; // Side
  324.        
  325.         Scanner volumecubechoiceone = new Scanner(System.in);
  326.        
  327.         System.out.println("\n");
  328.        
  329.         System.out.println("Enter The side Number:>>\t");
  330.         sidelength = volumecubechoiceone.nextInt();
  331.        
  332.         int cubevolanswerchoice = sidelength * sidelength * sidelength;
  333.         System.out.println("\n");
  334.         System.out.format("Answer:>>\t%d", cubevolanswerchoice);
  335.         System.out.println("\n");
  336.  
  337.     }
  338.    
  339.     public static void SphereVolumes() {
  340.        
  341.         int sidelength; // Side
  342.        
  343.         Scanner volumecubechoiceone = new Scanner(System.in);
  344.        
  345.         System.out.println("\n");
  346.        
  347.         System.out.println("Enter The side Number:>>\t");
  348.         sidelength = volumecubechoiceone.nextInt();
  349.        
  350.         int cubevolanswerchoice = sidelength * sidelength * sidelength;
  351.         System.out.println("\n");
  352.         System.out.format("Answer:>>\t%d", cubevolanswerchoice);
  353.         System.out.println("\n");
  354.  
  355.     }
  356.    
  357.     public static void CylinderVolumes() {
  358.        
  359.         int radiusone; // radius
  360.         int heightfour; // height
  361.        
  362.         Scanner cylindervolumesonechoice = new Scanner(System.in);
  363.        
  364.         System.out.println("\n");
  365.        
  366.         System.out.println("Enter The Radius Number:>>\t");
  367.         radiusone = cylindervolumesonechoice.nextInt();
  368.        
  369.         System.out.println("Enter The Height Number:>>\t");
  370.         heightfour = cylindervolumesonechoice.nextInt();
  371.        
  372.         int cylindervolumestwoohonechoice = (int) (Math.pow(radiusone, heightfour) * Math.PI * heightfour);
  373.         System.out.println("\n");
  374.         System.out.format("Answer:>>\t%d", cylindervolumestwoohonechoice);
  375.         System.out.println("\n");
  376.  
  377.     }
  378.    
  379.     //
  380.    
  381.     public static void RegularPrismVolumes() {
  382.        
  383.         int baseone; // base
  384.         int heightthree; // height
  385.        
  386.         Scanner regularprismvolumesonechoice = new Scanner(System.in);
  387.        
  388.         System.out.println("\n");
  389.        
  390.         System.out.println("Enter The Base Number:>>\t");
  391.         baseone = regularprismvolumesonechoice.nextInt();
  392.        
  393.         System.out.println("Enter The Height Number:>>\t");
  394.         heightthree = regularprismvolumesonechoice.nextInt();
  395.        
  396.         int regularprismvolumestwoohonechoice = baseone * heightthree;
  397.         System.out.println("\n");
  398.         System.out.format("Answer:>>\t%d", regularprismvolumestwoohonechoice);
  399.         System.out.println("\n");
  400.  
  401.     }
  402.    
  403.     //ConePyramidVolumes
  404.    
  405.     public static void ParallelepipedVolumes() {
  406.        
  407.         int lengtheight; // length
  408.         int widtheight; // width
  409.         int heighteight; // height
  410.        
  411.         Scanner parallelepipedvolumesonechoice = new Scanner(System.in);
  412.        
  413.         System.out.println("\n");
  414.        
  415.         System.out.println("Enter The Length Number:>>\t");
  416.         lengtheight = parallelepipedvolumesonechoice.nextInt();
  417.        
  418.         System.out.println("Enter The Width Number:>>\t");
  419.         widtheight = parallelepipedvolumesonechoice.nextInt();
  420.        
  421.         System.out.println("Enter The Height Number:>>\t");
  422.         heighteight = parallelepipedvolumesonechoice.nextInt();
  423.        
  424.         int parallelepipedvolumestwoohonechoice = lengtheight * widtheight * heighteight;
  425.         System.out.println("\n");
  426.         System.out.format("Answer:>>\t%d", parallelepipedvolumestwoohonechoice);
  427.         System.out.println("\n");
  428.  
  429.     }
  430.    
  431.     public static void ConePyramidVolumes() {
  432.        
  433.         int lengtheight; // length
  434.         int widtheight; // width
  435.         int heighteight; // height
  436.        
  437.         Scanner parallelepipedvolumesonechoice = new Scanner(System.in);
  438.        
  439.         System.out.println("\n");
  440.        
  441.         System.out.println("Enter The Length Number:>>\t");
  442.         lengtheight = parallelepipedvolumesonechoice.nextInt();
  443.        
  444.         System.out.println("Enter The Width Number:>>\t");
  445.         widtheight = parallelepipedvolumesonechoice.nextInt();
  446.        
  447.         System.out.println("Enter The Height Number:>>\t");
  448.         heighteight = parallelepipedvolumesonechoice.nextInt();
  449.        
  450.         int parallelepipedvolumestwoohonechoice = lengtheight * widtheight * heighteight;
  451.         System.out.println("\n");
  452.         System.out.format("Answer:>>\t%d", parallelepipedvolumestwoohonechoice);
  453.         System.out.println("\n");
  454.        
  455.     }
  456.    
  457.    
  458.  
  459.     public static void Formulas_And_Others() {
  460.         int formulasandothersonechoice;
  461.        
  462.         Scanner calculatorformulasone = new Scanner(System.in);
  463.        
  464.         System.out.println();
  465.        
  466.         System.out.println("Please Select An Option\n");
  467.        
  468.         System.out.println("[1] Areas\n");
  469.        
  470.         System.out.println("[2] Volumes\n");
  471.        
  472.         System.out.println("Option:>>\t");
  473.         formulasandothersonechoice = calculatorformulasone.nextInt();
  474.        
  475.         if (formulasandothersonechoice == 1) {
  476.            
  477.             int calculatorproblemfivechoice;
  478.  
  479.             Scanner calculatorfirstselectoptionselectiononechoice = new Scanner(System.in);
  480.  
  481.             System.out.println();
  482.            
  483.             System.out.println("\n");
  484.            
  485.             System.out.println("Please select an option\n");
  486.            
  487.             System.out.println("[1] Circle\n");
  488.            
  489.             System.out.println("[2] Sphere\n");
  490.            
  491.             System.out.println("[3] Square\n");
  492.            
  493.             System.out.println("[4] Rhombus\n");
  494.            
  495.             System.out.println("[5] Triangle\n");
  496.            
  497.             System.out.println("[6] Trapezoid\n");
  498.            
  499.             System.out.println("[7] Rectangle\n");
  500.  
  501.             System.out.println("Option:>>\t");
  502.             calculatorproblemfivechoice = calculatorfirstselectoptionselectiononechoice.nextInt();
  503.  
  504.             if (calculatorproblemfivechoice == 1) {
  505.                 CircleArea();
  506.             }
  507.             else if (calculatorproblemfivechoice == 2) {
  508.                 SphereArea();
  509.             }
  510.             else if (calculatorproblemfivechoice == 3) {
  511.                 SquareArea();
  512.             }
  513.             else if (calculatorproblemfivechoice == 4) {
  514.                 RhombusArea();
  515.             }
  516.             else if (calculatorproblemfivechoice == 5) {
  517.                 TriangleArea();
  518.             }
  519.             else if (calculatorproblemfivechoice == 6) {
  520.                 TrapezoidArea();
  521.             }
  522.             else if (calculatorproblemfivechoice == 7) {
  523.                 RectangleArea();
  524.             }
  525.         }
  526.        
  527.         if (formulasandothersonechoice == 2) {
  528.            
  529.             int calculatorproblemfivechoice;
  530.  
  531.             Scanner calculatorfirstselectoptionselectiononechoice = new Scanner(System.in);
  532.  
  533.             System.out.println();
  534.            
  535.             System.out.println("\n");
  536.            
  537.             System.out.println("Please select an option\n");
  538.            
  539.             System.out.println("[1] Cube\n");
  540.            
  541.             System.out.println("[2] Sphere\n");
  542.            
  543.             System.out.println("[3] Cylinder\n");
  544.            
  545.             System.out.println("[4] Regular prism\n");
  546.            
  547.             System.out.println("[5] Parallelepiped\n");
  548.            
  549.             System.out.println("[6] Cone (or pyramid)\n");
  550.            
  551.             System.out.println("Option:>>\t");
  552.             calculatorproblemfivechoice = calculatorfirstselectoptionselectiononechoice.nextInt();
  553.  
  554.             if (calculatorproblemfivechoice == 1) {
  555.                 CubeVolumes();
  556.             }
  557.             else if (calculatorproblemfivechoice == 2) {
  558.                 SphereVolumes();
  559.             }
  560.             else if (calculatorproblemfivechoice == 3) {
  561.                 CylinderVolumes();
  562.             }
  563.             else if (calculatorproblemfivechoice == 4) {
  564.                 RegularPrismVolumes();
  565.             }
  566.             else if (calculatorproblemfivechoice == 5) {
  567.                 ParallelepipedVolumes();
  568.             }
  569.             else if (calculatorproblemfivechoice == 6) {
  570.                 ConePyramidVolumes();
  571.             }
  572.         }
  573.     }
  574.    
  575.     public static void main(String[] args) {
  576.        
  577.         // TODO code application logic here
  578.         int calculatorproblemchoice;
  579.        
  580.         Scanner calculatorfirstselection = new Scanner(System.in);
  581.        
  582.         System.out.println();
  583.        
  584.         System.out.println("Calculator Program\n");
  585.  
  586.         System.out.println("Please select an option\n");
  587.        
  588.         System.out.println("[1] Division\n");
  589.        
  590.         System.out.println("[2] Addition\n");
  591.  
  592.         System.out.println("[3] Subtraction\n");
  593.        
  594.         System.out.println("[4] Floor Divison\n");
  595.        
  596.         System.out.println("[5] Multiplication\n");
  597.        
  598.         System.out.println("[6] Formulas, and other tools\n");
  599.        
  600.         System.out.println("Option:>>\t");
  601.         calculatorproblemchoice = calculatorfirstselection.nextInt();
  602.        
  603.         switch (calculatorproblemchoice) {
  604.             case 1:
  605.                 Division();
  606.                 break;
  607.             case 2:
  608.                 Addition();
  609.                 break;
  610.             case 3:
  611.                 Subtraction();
  612.                 break;
  613.             case 4:
  614.                 Floor_Divison();
  615.                 break;
  616.             case 5:
  617.                 Multiplication();
  618.                 break;
  619.             case 6:
  620.                 Formulas_And_Others();
  621.                 break;
  622.             default:
  623.                 break;
  624.         }
  625.     }
  626. }
  627.  
RAW Paste Data