kali ini saya akan berbagi tentang cara membuat konverter termometer dengan bahasa java.
dalam program ini penulis menggunakan java swing untuk tampilannya
silahkan:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package temp; import java.io.*; import javax.swing.JOptionPane; /** * * @author Arif */ public class Temp { /** * @param args the command line arguments */ public static void main(String[] args) { String input = ""; String temp1 = ""; String temp2 = ""; Integer user = 0; Integer user2= 0; input = JOptionPane.showInputDialog("masukkan angka"); temp1 = JOptionPane.showInputDialog("satuan derajat awal"); temp2 = JOptionPane.showInputDialog("satuan derajat tujuan"); Integer input1; input1 = Integer.parseInt(input); if (temp1.length() > 0);{ switch (temp1.charAt(0)){ case'C': case'c': user = 0; break; case'R': case'r': user = 1; break; case'K': case'k': user = 2; break; case'F': case'f': user = 3; break; } } if (temp2.length() > 0);{ switch (temp2.charAt(0)){ case'C': case'c': user2 = 0; break; case'R': case'r': user2 = 1; break; case'K': case'k': user2 = 2; break; case'F': case'f': user2 = 3; break; } } switch (user){ case 0: switch (user2){ case 0: JOptionPane.showMessageDialog(null, input1); break; case 1: JOptionPane.showMessageDialog(null, (4*input1)/5); break; case 2: JOptionPane.showMessageDialog(null, input1+273); break; case 3: JOptionPane.showMessageDialog(null, (9*input1)/5+32); break;} break; case 1: switch (user2){ case 0: JOptionPane.showMessageDialog(null, (5*input1)/4); break; case 1: JOptionPane.showMessageDialog(null, input1); break; case 2: JOptionPane.showMessageDialog(null, (5*input1)/4+273); break; case 3: JOptionPane.showMessageDialog(null, (9*((5*input1)/4)/5)+32); break;} break; case 2: switch (user2){ case 0: JOptionPane.showMessageDialog(null, input1-273); break; case 1: JOptionPane.showMessageDialog(null, (4*(input1-273)/5)); break; case 2: JOptionPane.showMessageDialog(null, input1); break; case 3: JOptionPane.showMessageDialog(null, ((9*(input1-273)))/5+32); break;} break; case 3: switch (user2){ case 0: JOptionPane.showMessageDialog(null, ((5*(input1-32))/9)); break; case 1: JOptionPane.showMessageDialog(null, (4*(5*(input1-32))/9)/5); break; case 2: JOptionPane.showMessageDialog(null, (((5*(input1-32))/9))+273); break; case 3: JOptionPane.showMessageDialog(null, input1); break;} break; } } }
0 komentar:
Posting Komentar