In: Computer Science
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user.
To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number.
Example:
12 times 55 divided by 50 equals 13.2 should round down to 13
for
55 KG
13 ml/Hour
12 times 57 divided by 50 equals 13.68 should round up to 14
for
55 KG
14 mL/hour
Use 55 and 57 kg as your test weight.
Sample output:
Weight in kg: 55 kg
Infusion of 13 ml/hour.
Weight in kg: 57 kg
Infusion of 14 ml/hour.
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Surya
*/
public class HEPCALC implements ActionListener
{
JFrame frame;
JLabel l1,l2;
JTextField t1;
JButton b1;
HEPCALC()
{
frame = new JFrame();
frame.setSize(new Dimension(300,300));
frame.setLayout(new FlowLayout());
l1 = new JLabel("Weight in kg:");
b1= new JButton("Calculate");
b1.addActionListener(this);
l2 = new JLabel("");
t1 = new JTextField(10);
JPanel p = new JPanel();
p.add(l1);
frame.add(l1);
frame.add(t1);
frame.add(b1);
frame.add(l2);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
//throw new UnsupportedOperationException("Not supported
yet.");
Integer d = Integer.parseInt(t1.getText());
//finding infusion
d = d*12/50;
int m =(int)d;
System.out.println(m);
l2.setText("Infusion of "+Integer.toString(m)+" ml/hour.");
frame.setVisible(true);
}
public static void main(String argv[])
{
new HEPCALC();
}
}
output: