kindly tell me whats wrong in simple laymans term....
together with this is a snapshot of the output program. kindly look at the thumbnail.....
plssssssssss..........
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class mp2f extends Applet implements ActionListener,ItemListener
{
int a;
Label booksLbl = new Label("Books Available:");
Checkbox hpBox = new Checkbox("Harry Potter",false);
Checkbox lotrBox = new Checkbox("Lord of the Rings",false);
Checkbox aiwBox = new Checkbox("Alice in Wonderland",false);
Checkbox pBox = new Checkbox("Prince",false);
Label qtyLbl = new Label("Quantity");
TextField qty1Txt = new TextField(10);
TextField qty2Txt = new TextField(10);
TextField qty3Txt = new TextField(10);
TextField qty4Txt = new TextField(10);
Label upLbl = new Label("Unit Price:");
Label up1Lbl = new Label("P 1500");
Label up2Lbl = new Label("P 1000");
Label up3Lbl = new Label("P 800");
Label up4Lbl = new Label("P 1600");
Label tpLbl = new Label("Total Price");
Label tp1Lbl = new Label("P");
Label tp2Lbl = new Label("P");
Label tp3Lbl = new Label("P");
Label tp4Lbl = new Label("P");
Label mopLbl = new Label("Mode of Payment:");
CheckboxGroup optGroup = new CheckboxGroup();
Checkbox cash = new Checkbox("Cash",false,optGroup);
Checkbox twop = new Checkbox("2 Payments(10%)",false,optGroup);
Checkbox threep = new Checkbox("3 Payments(20%)",false,optGroup);
Label tqLbl = new Label("Total Quantity:");
Label priceLbl = new Label("Price:");
Label interestLbl = new Label("Interest:");
Label taLbl = new Label("Total Amount:");
Button okButton = new Button("OK");
Button resetButton = new Button("RESET");
public void init()
{
add(booksLbl);
add(hpBox);
hpBox.addItemListener(this);
add(lotrBox);
lotrBox.addItemListener(this);
add(aiwBox);
aiwBox.addItemListener(this);
add(pBox);
pBox.addItemListener(this);
add(qtyLbl);
add(qty1Txt);
add(qty2Txt);
add(qty3Txt);
add(qty4Txt);
add(upLbl);
add(up1Lbl);
add(up2Lbl);
add(up3Lbl);
add(up4Lbl);
add(tpLbl);
add(tp1Lbl);
add(tp2Lbl);
add(tp3Lbl);
add(tp4Lbl);
add(mopLbl);
add(cash);
cash.addItemListener(this);
add(twop);
twop.addItemListener(this);
add(threep);
threep.addItemListener(this);
add(tqLbl);
add(priceLbl);
add(interestLbl);
add(okButton);
okButton.addActionListener(this);
add(resetButton);
resetButton.addActionListener(this);
}
public void itemStateChanged(ItemEvent e)
{
if(cash.getState())
a=1;
if(twop.getState())
a=2;
if(threep.getState())
a=3;
}
public void actionPerformed(ActionEvent e)
{
String arg;
int tq,price,up1=0,up2=0,up3=0,up4=0,qty1,qty2,qty3,qty4,tp1,tp2,tp3,tp4;
double interest=0,ta;
qty1=Integer.parseInt(qty1Txt.getText());
qty2=Integer.parseInt(qty2Txt.getText());
qty3=Integer.parseInt(qty3Txt.getText());
qty4=Integer.parseInt(qty4Txt.getText());
tp1=Integer.parseInt(tp1Lbl.getText());
tp2=Integer.parseInt(tp2Lbl.getText());
tp3=Integer.parseInt(tp3Lbl.getText());
tp4=Integer.parseInt(tp4Lbl.getText());
arg=e.getActionCommand();
if(arg=="OK")
{
up1=1500;
tp1=qty1*up1;
tp1Lbl.setText("P " +tp1);
up2=1000;
tp2=qty2*up2;
tp2Lbl.setText("P " +tp2);
up3=800;
tp3=qty3*up3;
tp3Lbl.setText("P " +tp3);
up4=1600;
tp4=qty4*up4;
tp4Lbl.setText("P " +tp4);
if(cash.getState())
{
tq=(qty1) + (qty2) + (qty3) + (qty4);
tqLbl.setText("Total Quantity: "+tq);
price=(tp1) + (tp2) + (tp4) + (tp4);
priceLbl.setText("Price: "+price);
interestLbl.setText("Interest: 0");
ta=price+interest;
taLbl.setText("Total Amount: "+ta);
}
if(twop.getState())
{
tq=(qty1) + (qty2) + (qty3) + (qty4);
tqLbl.setText("Total Quantity: "+tq);
price=(tp1) + (tp2) + (tp4) + (tp4);
priceLbl.setText("Price: "+price);
interest=(price) * 0.1;
interestLbl.setText("Interest: "+interest);
ta=price+interest;
taLbl.setText("Total Amount: "+ta);
}
if(threep.getState())
{
tq=(qty1) + (qty2) + (qty3) + (qty4);
tqLbl.setText("Total Quantity: "+tq);
price=(tp1) + (tp2) + (tp4) + (tp4);
priceLbl.setText("Price: "+price);
interest=(price) * 0.2;
interestLbl.setText("Interest: "+interest);
ta=price+interest;
taLbl.setText("Total Amount: "+ta);
}
}
if(arg=="RESET")
{
hpBox.setState(false);
lotrBox.setState(false);
aiwBox.setState(false);
pBox.setState(false);
qty1Txt.setText(" ");
qty2Txt.setText(" ");
qty3Txt.setText(" ");
qty4Txt.setText(" ");
tp1Lbl.setText("P");
tp2Lbl.setText("P");
tp3Lbl.setText("P");
tp4Lbl.setText("P");
cash.setState(false);
twop.setState(false);
threep.setState(false);
tqLbl.setText("Total Quantity:");
priceLbl.setText("Price:");
interestLbl.setText("Interest:");
taLbl.setText("Total Amount:");
}
}
}

New Topic/Question
Reply




MultiQuote






|