714/5000
Hello again, here I bring a preview of an application that I am working on, this is an erasure of what will be just a mini function to make conversions of units of mass, the long-term idea is to make a great application that will allow us perform calculations, analysis, graphs, etc. of Secondary and University Physics problems.
The algorithm: it is simple is based on the use of float variables, to save momoria space, and the use of the structure in case, or "switch case".
I took this graph as a reference that gives us an idea of what is being executed (it is not a flow diagram at all, it is only the graphic reference to perform the calculations)
package conversor.de.unidades.de.masa;
import javax.swing.JOptionPane;
/**
@author ROBERT
*/
public class ConversorDeUnidadesDeMasa {/**
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic herefloat gramo,decigramo,centigramo,miligramo,decagramo,hectogramo,kilogramo,conversion;
int opcion_p,opcion_kg,opcion_hg,opcion_dag,opcion_g,opcion_dg,opcion_cg,opcion_mg;opcion_p=Integer.parseInt(JOptionPane.showInputDialog(null, "Conversor de Unidades de Masa\n\n"
+"1)Kilogramo\n"
+ "2)Hectogramo\n"
+ "3)Decagramo\n"
+ "4)Gramo\n"
+ "5)Decigramo\n"
+ "6)Centigramo\n"
+ "7)Miligramo\n"
+ "8)Salir"));switch(opcion_p) {
case 1:kilogramo=Float.parseFloat(JOptionPane.showInputDialog(null, "Digite cantidad en kg"));
opcion_kg=Integer.parseInt(JOptionPane.showInputDialog(null, "Convertir a: \n"
+ "1)Hectogramo\n"
+ "2)Decagramo\n"
+ "3)Gramo\n"
+ "4)Decigramo\n"
+ "5)Centigramo\n"
+ "6)Miligramo\n"));
switch(opcion_kg) {
case 1: conversion=kilogramo10;
JOptionPane.showMessageDialog(null, +conversion+" hg");
break;
case 2:conversion=kilogramo100;
JOptionPane.showMessageDialog(null, +conversion+" dag");
break;
case 3:conversion=kilogramo1000;
JOptionPane.showMessageDialog(null, +conversion+" g");
break;
case 4:conversion=kilogramo10000;
JOptionPane.showMessageDialog(null, +conversion+" dg");
break;
case 5:conversion=kilogramo100000;
JOptionPane.showMessageDialog(null, +conversion+" cg");
break;
case 6:conversion=kilogramo1000000;
JOptionPane.showMessageDialog(null, +conversion+" mg");
break;
default:
JOptionPane.showMessageDialog(null, "Opcion Invalida");
break;}
case 2:hectogramo=Float.parseFloat(JOptionPane.showInputDialog(null, "Digite cantidad en hg"));
opcion_hg=Integer.parseInt(JOptionPane.showInputDialog(null, "Convertir a: \n"
+ "1)Kilogramo\n"
+ "2)Decagramo\n"
+ "3)Gramo\n"
+ "4)Decigramo\n"
+ "5)Centigramo\n"
+ "6)Miligramo\n"));
switch(opcion_hg) {
case 1: conversion=hectogramo/10;
JOptionPane.showMessageDialog(null, +conversion+" kg");
break;
case 2:conversion=hectogramo10;
JOptionPane.showMessageDialog(null, +conversion+" dag");
break;
case 3:conversion=hectogramo100;
JOptionPane.showMessageDialog(null, +conversion+" g");
break;
case 4:conversion=hectogramo1000;
JOptionPane.showMessageDialog(null, +conversion+" dg");
break;
case 5:conversion=hectogramo10000;
JOptionPane.showMessageDialog(null, +conversion+" cg");
break;
case 6:conversion=hectogramo100000;
JOptionPane.showMessageDialog(null, +conversion+" mg");
break;
default:
JOptionPane.showMessageDialog(null, "Opcion Invalida");
break;
}
case 3:decagramo=Float.parseFloat(JOptionPane.showInputDialog(null, "Digite cantidad en dag"));
opcion_dag=Integer.parseInt(JOptionPane.showInputDialog(null, "Convertir a: \n"
+ "1)Kilogramo\n"
+ "2)Hectogramo\n"
+ "3)Gramo\n"
+ "4)Decigramo\n"
+ "5)Centigramo\n"
+ "6)Miligramo\n"));
switch(opcion_dag) {
case 1: conversion=decagramo/100;
JOptionPane.showMessageDialog(null, +conversion+" kg");
break;
case 2:conversion=decagramo/10;
JOptionPane.showMessageDialog(null, +conversion+" hg");
break;
case 3:conversion=decagramo10;
JOptionPane.showMessageDialog(null, +conversion+" g");
break;
case 4:conversion=decagramo100;
JOptionPane.showMessageDialog(null, +conversion+" dg");
break;
case 5:conversion=decagramo1000;
JOptionPane.showMessageDialog(null, +conversion+" cg");
break;
case 6:conversion=decagramo*10000;
JOptionPane.showMessageDialog(null, +conversion+" mg");
break;
default:
JOptionPane.showMessageDialog(null, "Opcion Invalida");
break;
}case 4:gramo=Float.parseFloat(JOptionPane.showInputDialog(null, "Digite cantidad en g"));
opcion_g=Integer.parseInt(JOptionPane.showInputDialog(null, "Convertir a: \n"
+ "1)Kilogramo\n"
+ "2)Hectogramo\n"
+ "3)decagramo\n"
+ "4)Decigramo\n"
+ "5)Centigramo\n"
+ "6)Miligramo\n"));
switch(opcion_g) {
case 1: conversion=gramo/1000;
JOptionPane.showMessageDialog(null, +conversion+" kg");
break;
case 2:conversion=gramo/100;
JOptionPane.showMessageDialog(null, +conversion+" hg");
break;
case 3:conversion=gramo/10;
JOptionPane.showMessageDialog(null, +conversion+" dag");
break;
case 4:conversion=gramo10;
JOptionPane.showMessageDialog(null, +conversion+" dg");
break;
case 5:conversion=gramo100;
JOptionPane.showMessageDialog(null, +conversion+" cg");
break;
case 6:conversion=gramo1000;
JOptionPane.showMessageDialog(null, +conversion+" mg");
break;
default:
JOptionPane.showMessageDialog(null, "Opcion Invalida");
break;
}
case 5:decigramo=Float.parseFloat(JOptionPane.showInputDialog(null, "Digite cantidad en dg"));
opcion_dg=Integer.parseInt(JOptionPane.showInputDialog(null, "Convertir a: \n"
+ "1)Kilogramo\n"
+ "2)Hectogramo\n"
+ "3)decagramo\n"
+ "4)gramo\n"
+ "5)Centigramo\n"
+ "6)Miligramo\n"));
switch(opcion_dg) {
case 1: conversion=decigramo/10000;
JOptionPane.showMessageDialog(null, +conversion+" kg");
break;
case 2:conversion=decigramo/1000;
JOptionPane.showMessageDialog(null, +conversion+" hg");
break;
case 3:conversion=decigramo/100;
JOptionPane.showMessageDialog(null, +conversion+" dag");
break;
case 4:conversion=decigramo/10;
JOptionPane.showMessageDialog(null, +conversion+" g");
break;
case 5:conversion=decigramo10;
JOptionPane.showMessageDialog(null, +conversion+" cg");
break;
case 6:conversion=decigramo100;
JOptionPane.showMessageDialog(null, +conversion+" mg");
break;
default:
JOptionPane.showMessageDialog(null, "Opcion Invalida");
break;
}
case 6:centigramo=Float.parseFloat(JOptionPane.showInputDialog(null, "Digite cantidad en cg"));
opcion_cg=Integer.parseInt(JOptionPane.showInputDialog(null, "Convertir a: \n"
+ "1)Kilogramo\n"
+ "2)Hectogramo\n"
+ "3)decagramo\n"
+ "4)gramo\n"
+ "5)decigramo\n"
+ "6)Miligramo\n"));
switch(opcion_cg) {
case 1: conversion=centigramo/100000;
JOptionPane.showMessageDialog(null, +conversion+" kg");
break;
case 2:conversion=centigramo/10000;
JOptionPane.showMessageDialog(null, +conversion+" hg");
break;
case 3:conversion=centigramo/1000;
JOptionPane.showMessageDialog(null, +conversion+" dag");
break;
case 4:conversion=centigramo/100;
JOptionPane.showMessageDialog(null, +conversion+" g");
break;
case 5:conversion=centigramo/10;
JOptionPane.showMessageDialog(null, +conversion+" dg");
break;
case 6:conversion=centigramo10;
JOptionPane.showMessageDialog(null, +conversion+" mg");
break;
default:
JOptionPane.showMessageDialog(null, "Opcion Invalida");
break;
}
case 7:miligramo=Float.parseFloat(JOptionPane.showInputDialog(null, "Digite cantidad en mg"));
opcion_mg=Integer.parseInt(JOptionPane.showInputDialog(null, "Convertir a: \n"
+ "1)Kilogramo\n"
+ "2)Hectogramo\n"
+ "3)Decagramo\n"
+ "4)Gramo\n"
+ "5)Decigramo\n"
+ "6)Centigramo\n"));
switch(opcion_mg) {
case 1: conversion=miligramo/1000000;
JOptionPane.showMessageDialog(null, +conversion+" kg");
break;
case 2:conversion=miligramo/100000;
JOptionPane.showMessageDialog(null, +conversion+" hg");
break;
case 3:conversion=miligramo/10000;
JOptionPane.showMessageDialog(null, +conversion+" dag");
break;
case 4:conversion=miligramo/1000;
JOptionPane.showMessageDialog(null, +conversion+" g");
break;
case 5:conversion=miligramo/100;
JOptionPane.showMessageDialog(null, +conversion+" dg");
break;
case 6:conversion=miligramo/10;
JOptionPane.showMessageDialog(null, +conversion+" cg");
break;
default:
JOptionPane.showMessageDialog(null, "Opcion Invalida");
break;
}
case 8:
break;
}
}
}
Congratulations @hydrastudio99! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
You published 4 posts in one day
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP