In: Computer Science
Create in java an interactive GUI application program that will prompt the user to use one of three calculators, label project name MEDCALC. You can use any color you want for your background other than grey. Be sure to label main java box with “MEDCALC” and include text of “For use only by students”
On all three calculators create an alert and signature area for each user. The alert should be something like “All calculations must be confirmed by user before use.” The user will need to sign acknowledging the alert before they are allowed to move on to use the calculator; at this point your program should also write to a file on the user’s local computer, capturing data of date and name signed (this can be a text file or excel file). Again, User should not be able to use any of the calculators if they do not provide name.
Calculator one is CALC1, Calculator two is CALC2, Calculator three is CALC3. (CALC3 will be created later)
Calculator one: Be sure to label “CALC1”
Prompt user to enter a weight for a patient in kilograms. Calculate both bolus and infusion rates based on weight of patient. The patient’s weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the total number is less than 3999, then the BOLUS is the total number else it is 4000 Use 19.99 as a standard for calculating Maintenance infusion: To calculate the Maintenance infusion you will multiply 12 times the weight divided by 50 for a total number. IF the total number is less than 19.99 then the Maintenance infusion is the total number else it is 20 Use 50 and 100 KG as your test weight.
Two sample outputs: (user should see this data displayed)
Weight in kg: 50.00 kg
BOLUS 3000 units
Maintenance infusion of 12 ml/hour
Weight in kg: 100.00 kg
BOLUS 4000 units
Maintenance infusion of 20 ml/hour
Calculator two: Be sure to label “CALC2”
Prompt user to enter a weight for a patient in kilograms. Calculate infusion rate based on weight of patient.
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.
Two sample outputs: (user should see this data displayed)
Weight in kg: 55 kg
Infusion of 13 ml/hour
Weight in kg: 57 kg
Infusion of 14 ml/hour
package GUI;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
// Defines a class MEDCALC
public class MEDCALC
{
// Declares container and component objects
private JFrame jf;
private JPanel jp1, jp2, mainP;
private JTextArea result;
private JButton CALC1, CALC2;
// Default constructor definition
MEDCALC()
{
// Creates a frame
jf = new JFrame("MEDCALC");
// Creates panels
jp1 = new JPanel();
jp2 = new JPanel();
mainP = new JPanel();
// Creates text area
result = new JTextArea(4, 20);
// Creates buttons
CALC1 = new JButton("CALC1");
CALC2 = new JButton("CALC2");
// Adds the buttons to panel 1
jp1.add(CALC1);
jp1.add(CALC2);
// Adds the text area to panel 2
jp2.add(result);
// Adds the panels to main panel
mainP.add(jp1);
mainP.add(jp2);
// Sets the layout to grid layout with 2 row and 1 column
mainP.setLayout(new GridLayout(2, 1));
// Adds the main panel to frame
jf.add(mainP);
// Sets the background color of the panels
jp1.setBackground(Color.RED);
jp2.setBackground(Color.BLUE);
// Sets the frame visible property to true
jf.setVisible(true);
// Set the size of the frame to width 400 and height 200
jf.setLocationRelativeTo(null);
jf.pack();
// Registers action listener to CALC1 button using anonymous class
CALC1.addActionListener(new ActionListener()
{
// Overrides the actionPerformed() method of ActionListener interface
public void actionPerformed(ActionEvent ae)
{
int bolus;
int infusion;
// Accepts weight from the user
int weight = Integer.parseInt(JOptionPane.showInputDialog(jf,
"Enter a weight for a patient in kilograms: "));
// Calculates total number for bolus
int totalNumber = weight * 60;
// Checks if total number is less than 3999
if(totalNumber < 3999)
// Assign total number to bolus
bolus = totalNumber;
// Otherwise assign 4000 to bolus
else
bolus = 4000;
// Calculates total number for infusion
totalNumber = weight * 12 / 50;
// Checks if total number is less than 19.99
if(totalNumber < 19.99)
// Assign total number to infusion
infusion = totalNumber;
// Otherwise assign 20 to infusion
else
infusion = 20;
// Sets the result to text area
result.setText(" Weight in kg: " + weight + " kg"
+ "\n BOLUS " + bolus + " units"
+ "\n Maintenance infusion of " + infusion + " ml/hour");
}// End of method
});// End of anonymous class
// Registers action listener to CALC2 button using anonymous class
CALC2.addActionListener(new ActionListener()
{
// Overrides the actionPerformed() method of ActionListener interface
public void actionPerformed(ActionEvent ae)
{
// Accepts weight from the user
int weight = Integer.parseInt(JOptionPane.showInputDialog(jf,
"Enter a weight for a patient in kilograms: "));
// Calculates the infusion and rounds the result
int infusion = (int)Math.round(weight * 12.0 / 50.0);
// Sets the result to text area
result.setText(" Weight in kg: " + weight + " kg"
+ "\n Maintenance infusion of " + infusion + " ml/hour");
}// End of method
});// End of anonymous class
}// End of default constructor
// main method definition
public static void main(String ss[])
{
// Calls the default constructor
new MEDCALC();
}// End of main method
}// End of class
Sample Output: