• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java application JInsurance  RSS feed

 
sello skhalo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write an application that allows the
user to choose insurance options in
JCheckBoxes. Use a ButtonGroup to
allow the user to select only one of
two
insurance types—HMO (health maintenance organization) or PPO
(preferred
provider organization). Use regular
(single) JCheckBoxes for dental
insurance and vision insurance
options; the user can select one option,
both options, or neither option. As
the user selects each option, display
its name and price in a text field; the
HMO costs R200 per month, the PPO
costs R600 per month, the dental coverage adds R75 per month, and
the
vision care adds R20 per month.
When a user deselects an item, make
the
text field blank. Save the file as JInsurance.java.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's your question?
 
sello skhalo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I need some help with this. I
have done something wrong here
and I have no idea how to fix it. I
am confused aoout the total price
of the whole thing and how to go
about coding it. Please take a look and let me what I need change to
get this thing to work... import javax.swing.*;
import java.awt.*;
import java.awt.event.*; public class JInsurance extends
JFrame implements ItemListener
{
int hmoPrice = 200, ppoPrice =
800;
int[] additPrice ={0,20,75}; int basePrice = 0, totalPrice =
basePrice; JCheckBox hmoBox = new
JCheckBox("HMO $" + hmoPrice,
false);
JCheckBox ppoBox = new
JCheckBox("PPO $" + ppoPrice,
false); JLabel additLabel = new JLabel
("Additional Coverage: Make a
selection");
String[] additNames = {"None $"
+ additPrice[0], "Vision $" +
additPrice[1], "Dental $" + additPrice[2]};
JComboBox additBox = new
JComboBox(additNames); JLabel insOptionsLabel = new
JLabel("Insurance Options:");
JTextField totPrice = new
JTextField(10);
JTextField message = new
JTextField(30); JLabel optionExplainLabel =
new JLabel("Base price for
insurance with HMO $" + basePrice
+ ".");
JLabel optionExplainLabel2 =
new JLabel("Optionally, you can choose HMO or PPO only"); public JInsurance()
{
super("Insurance Price
Estimator");
setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE); JPanel pane = new JPanel();
ButtonGroup insGroup = new
ButtonGroup();
insGroup.add(hmoBox);
insGroup.add(ppoBox);
pane.add(hmoBox); pane.add(ppoBox);
pane.add(additLabel);
pane.add(additBox);
pane.add(insOptionsLabel);
pane.add
(optionExplainLabel); pane.add
(optionExplainLabel2);
pane.add(totPrice);
pane.add(message);
totPrice.setText("$" +
totalPrice); hmoBox.addItemListener
(this);
ppoBox.addItemListener
(this);
additBox.addItemListener
(this); setContentPane(pane);
}
public static void main(String[]
args)
{
JFrame aFrame = new JInsurance();
aFrame.setSize(400,250);
aFrame.setVisible(true);
}
public void itemStateChanged
(ItemEvent event) {
Object source =
event.getSource();
int select =
event.getStateChange(); if(source == additBox)
{
int addNum =
additBox.getSelectedIndex();
addPrice = additPrice
[addNum]; message.setText("Action:
Insurance options changed $" +
addPrice + " added");
}
else
message.setText("Action: Insurance type changed");
totalPrice = basePrice
+additPrice;
if(ppoBox.isSelected())
totalPrice +=
ppoPrice; else if
(fishBox.isSelected())
totalPrice +=
fishPrice; }
}
 
sello skhalo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone who can help me please
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PatienceIsAVirtue. And could you please UseCodeTags? That makes your code much easier to read.
 
sello skhalo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea but i dont know how to do it,i dnt knw where to find usecode tag
if you instruct me i can try
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!