Advertisement
Guest User

Ohm's Law Calculator - Main Class

a guest
Oct 12th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.79 KB | None | 0 0
  1. //Main Class
  2. import javax.swing.JOptionPane;
  3.  
  4. public class Main extends response
  5. {
  6.     public static void main(String[] args)
  7.     {
  8.         response obj = new response();
  9.         Mathoutput outputobj = new Mathoutput();
  10.  
  11.         String input = "";
  12.         int solvefor = 0;
  13.         input = JOptionPane.showInputDialog(null, "What unit are you solving for?\nPower,"
  14.                 + " Voltage, Current, Or Resistance?\nType the in variable you are solving for to select.   ");
  15.        
  16.  
  17.         if(!(input != null && !input.isEmpty()))
  18.             {
  19.             JOptionPane.showMessageDialog(null,"No Imput found!","Input Error",JOptionPane.WARNING_MESSAGE);
  20.             }
  21.         else
  22.             {  
  23.             if(input.equalsIgnoreCase("Power"))
  24.                 {
  25.                 solvefor = 1;
  26.                 }
  27.             if(input.equalsIgnoreCase("Voltage"))
  28.                 {
  29.                 solvefor = 2;
  30.                 }
  31.             if(input.equalsIgnoreCase("Current"))
  32.                 {
  33.                 solvefor = 3;
  34.                 }
  35.             if(input.equalsIgnoreCase("Resistance"))
  36.                 {
  37.                 solvefor = 4;
  38.                 }
  39.  
  40.             }
  41.        
  42.         //Generate variable selector
  43.         switch(solvefor)
  44.         {
  45.         case 1:
  46.         input = JOptionPane.showInputDialog(null,"[Solving for Power]\nFrom the entries below, "
  47.                 + "choose the option that contains \nthe variables that you currently have. To Select: "
  48.                 + "Type \nthe numeric value of the option to enter a selection. "
  49.                 + "\n\nOption #1: Voltage & Resistance"
  50.                 + "\nOption #2: Resistance & Current"
  51.                 + "\nOption #3: Voltage & Current");   
  52.         break;
  53.         case 2:
  54.         input = JOptionPane.showInputDialog(null,"[Solving for Voltage]\nFrom the entries below, "
  55.                 + "choose the option that contains \nthe variables that you currently have. To Select: "
  56.                 + "Type \nthe numeric value of the option to enter a selection. "
  57.                 + "\n\nOption #1: Resistance & Current"
  58.                 + "\nOption #2: Power & Current"
  59.                 + "\nOption #3: Power & Resistance");          
  60.         break;
  61.         case 3:
  62.         input = JOptionPane.showInputDialog(null,"[Solving for Current]\nFrom the entries below, "
  63.                 + "choose the option that contains \nthe variables that you currently have. To Select: "
  64.                 + "Type \nthe numeric value of the option to enter a selection. "
  65.                 + "\n\nOption #1: Power & Resistance"
  66.                 + "\nOption #2: Power & Voltage"
  67.                 + "\nOption #3: Voltage & Resistance");    
  68.         break;
  69.         case 4:
  70.         input = JOptionPane.showInputDialog(null,"[Solving for Resistance]\nFrom the entries below, "
  71.                 + "choose the option that contains \nthe variables that you currently have. To Select: "
  72.                 + "Type \nthe numeric value of the option to enter a selection. "
  73.                 + "\n\nOption #1: Power & Current"
  74.                 + "\nOption #2: Voltage & Power"
  75.                 + "\nOption #3: Voltage & Current");
  76.         break;
  77.         }
  78.    
  79.         double optionselection = Double.parseDouble(input);
  80.        
  81.         obj.does(solvefor,optionselection,input);
  82.    
  83.         outputobj.createfinaloutput(obj.power,obj.voltage,obj.current,obj.resistance,solvefor,optionselection);
  84.        
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement