Basically, I have a price quoter that I am working on. The way it should work is:
The user selects the quantity of cards from the combo box.
In the textfield a price displays once selected. (i.e. 100 = \$8.95).
(I have this segment working already.)
Next the user selects whether they need both sides of the card printed on or not.
Updated price displays. (i.e. 100 + both sides = \$11.95)
Next comes the delivery timeframe (i.e. 100 + both + two days = 38.95)
And finally whether they need us to design their card or not (100 + both + 2 days + yes = 53.95)

I've been working at this for awhile now, and have determined the best way to go about this is to have if statements add values to the initial value. (i.e. 100 = 8.95, both = +3, two = +27, yes = +15, total =53.95)
The sides and delivery values depends on the selected quantity.

Any and all help is greatly appreciated. Here is the code:

``````import javax.swing.*;
import java.awt.event.*;

public class BCard extends JFrame
{
private JPanel panel;
//I commented these out until I can fix the problems in the code//

//private JPanel panel2;
//private JPanel panel3;
//private JPanel panel4;
// private JPanel panel5;
//private JPanel panel6;
//private JPanel panel7;
private JLabel msgLbl;
private JLabel lbl;
private JLabel lbl2;
private JTextField bCTotal;
private String[] bC = {"100", "250", "500", "1000", "2000"};
private JComboBox bCQty;
private final int WINDOW_WIDTH = 300;
private final int WINDOW_HEIGHT = 200;
boolean value = true;
//double oneHun = 8.95;
//double twoFif = 11.95;
//double fiveHun = 12.95;
//double oneThou = 13.95;
//double twoThou = 27.95;
//String oneHunS = Double.toString(oneHun);
//String twoFifS = Double.toString(twoFif);
//String fiveHunS = Double.toString(fiveHun);
//String oneThouS = Double.toString(oneThou);
//String twoThouS = Double.toString(twoThou);
//double bCTot = 0;
//double bCP = 0;
//double deliv = 0;
//double sides = 0;
//double design = 0;
//String bCTotl = Double.toString(bCTot);

public BCard()
{
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildBCPanel();
setVisible(value);

}

private void buildBCPanel()
{
msgLbl = new JLabel("Select the criteria that fits your needs:");
//Number of cards
lbl = new JLabel("Quantity:");
bCQty = new JComboBox(bC);
//One or both sides printed
//types of cards
//shipping time
wksB = new JRadioButton("Up to Two Weeks");
// Need us to design card?
//Price quote
lbl2 = new JLabel("Your total may be \$");
bCTotal = new JTextField(10);
bCTotal.setEditable(false);

panel = new JPanel();
//panel2 = new JPanel();
//panel3 = new JPanel();
//panel4 = new JPanel();
// panel5 = new JPanel();
// panel6 = new JPanel();
//panel7 = new JPanel();
}

private class ComboListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
//turn double into string so it will show up in the JTextField
double oneHun = 8.95;
double twoFif = 11.95;
double fiveHun = 12.95;
double oneThou = 13.95;
double twoThou = 27.95;
String oneHunS = Double.toString(oneHun);
String twoFifS = Double.toString(twoFif);
String fiveHunS = Double.toString(fiveHun);
String oneThouS = Double.toString(oneThou);
String twoThouS = Double.toString(twoThou);
JComboBox comboBox=(JComboBox) e.getSource();
String s =(String) comboBox.getItemAt(comboBox.getSelectedIndex());

if(bCQty.getSelectedItem() == "100")
{
bCTotal.setText(oneHunS);
}
else if(bCQty.getSelectedItem() == "250")
{
bCTotal.setText(twoFifS);
}
else if(bCQty.getSelectedItem() == "500")
{
bCTotal.setText(fiveHunS);
}
else if(bCQty.getSelectedItem() == "1000")
{
bCTotal.setText(oneThouS);
}
else if(bCQty.getSelectedItem() == "2000")
{
bCTotal.setText(twoThouS);
}

}

}

{
public void actionPerformed (ActionEvent e)
{
double oneHunB = 3.00;
double twoFifB = 1.00;
double fiveHunB = 1.00;
double oneThouB = 2.00;
double twoThouB = 4.00;

if(e.getSource() == bothB && bCQty.getSelectedItem() == "100")
{
//sides = oneHunB;

}
else if(e.getSource() == bothB && bCQty.getSelectedItem() == "250")
{
//sides = twoFifB;
}
else if(e.getSource() == bothB && bCQty.getSelectedItem() == "250")
{
//sides = fiveHunB;
}
else if(e.getSource() == bothB && bCQty.getSelectedItem() == "1000")
{
//sides = oneThouB;
}
else if(e.getSource() == bothB && bCQty.getSelectedItem() == "2000")
{
//sides = twoThouB;
}

}
}

{
public void actionPerformed (ActionEvent e)
{
double oneHunD = 27;
double twoFifD = 29;
double fiveHunD = 33;
double oneThouD = 41;
double twoThouD = 57;

if(e.getSource() == twoDB && bCQty.getSelectedItem() == "100")
{
//deliv = oneHunD;
}
else if(e.getSource() == twoDB && bCQty.getSelectedItem() == "250")
{
//deliv = twoFifD;
}
else if(e.getSource() == twoDB && bCQty.getSelectedItem() == "500")
{
//deliv = fiveHunD;
}
else if(e.getSource() == twoDB && bCQty.getSelectedItem() == "1000")
{
//deliv = oneThouD;
}
else if(e.getSource() == twoDB && bCQty.getSelectedItem() == "2000")
{
//deliv = twoThouD;
}
}
}

//private class TotalListener implements ActionListener
{
//public void actionPerformed (ActionEvent e)
{
//bCTot = bCP + deliv + sides + design;
//bCTotal.setText(bCTotl);

}
}

public static void main(String[] args)
{
BCard bCard = new BCard();

}
}``````

are those all inner classes?

At first glance you code shold look like:

``````import javax.swing.*;
import java.awt.event.*;

public class BCard extends JFrame {

private JPanel panel;
//I commented these out until I can fix the problems in the code//
//private JPanel panel2;
//private JPanel panel3;
//private JPanel panel4;
// private JPanel panel5;
//private JPanel panel6;
//private JPanel panel7;
private JLabel msgLbl;
private JLabel lbl;
private JLabel lbl2;
private JTextField bCTotal;
private String[] bC = {"100", "250", "500", "1000", "2000"};
private JComboBox bCQty;
private final int WINDOW_WIDTH = 300;
private final int WINDOW_HEIGHT = 200;
boolean value = true;
double oneHunB = 3.00;
double twoFifB = 1.00;
double fiveHunB = 1.00;
double oneThouB = 2.00;
double twoThouB = 4.00;
double oneHun = 8.95;
double twoFif = 11.95;
double fiveHun = 12.95;
double oneThou = 13.95;
double twoThou = 27.95;
//initialize quantitePrice to oneHun
private double quantitePrice = oneHun;
private double sidePrice;
private double deliv;

public BCard() {
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildBCPanel();
setVisible(value);

}

private void buildBCPanel() {
msgLbl = new JLabel("Select the criteria that fits your needs:");
//Number of cards
lbl = new JLabel("Quantity:");
bCQty = new JComboBox(bC);
//One or both sides printed
//types of cards
//shipping time
wksB = new JRadioButton("Up to Two Weeks");
// Need us to design card?
//Price quote
lbl2 = new JLabel("Your total may be \$");
bCTotal = new JTextField(10);
bCTotal.setEditable(false);

panel = new JPanel();
//panel2 = new JPanel();
//panel3 = new JPanel();
//panel4 = new JPanel();
// panel5 = new JPanel();
// panel6 = new JPanel();
//panel7 = new JPanel();
}

private class ComboListener implements ActionListener {

public void actionPerformed(ActionEvent e) {
//turn double into string so it will show up in the JTextField

if (bCQty.getSelectedItem() == "100") {
quantitePrice = oneHun;
} else if (bCQty.getSelectedItem() == "250") {
quantitePrice = twoFif;
} else if (bCQty.getSelectedItem() == "500") {
quantitePrice = fiveHun;
} else if (bCQty.getSelectedItem() == "1000") {
quantitePrice = oneThou;
} else if (bCQty.getSelectedItem() == "2000") {
quantitePrice = twoThou;
}
updateResult();
}
}
//ComboListener will be more shorter if using an array

/*private class ComboListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
double[] quantitePrices = {8.95, 11.95, 12.95, 13.95, 27.95};
JComboBox comboBox = (JComboBox) e.getSource();
quantitePrice = quantitePrices[comboBox.getSelectedIndex()];
updateResult();
}
}*/
private class RadioButtonListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

//Here it is supposed that if the one side the the sides value is set to 0.
if (e.getSource() == oneB) {
sidePrice = 0;

} else {
if (e.getSource() == bothB) {
if (/*e.getSource() == bothB &&*/bCQty.getSelectedItem() == "100") {
sidePrice = oneHunB;
} else if (/*e.getSource() == bothB &&*/bCQty.getSelectedItem() == "250") {
sidePrice = twoFifB;
} else if (/*e.getSource() == bothB &&*/bCQty.getSelectedItem() == "250") {
sidePrice = fiveHunB;
} else if (/*e.getSource() == bothB &&*/bCQty.getSelectedItem() == "1000") {
sidePrice = oneThouB;
} else if (/*e.getSource() == bothB &&*/bCQty.getSelectedItem() == "2000") {
sidePrice = twoThouB;
}
}
}
updateResult();
}
}

private class RadioButtonListener2 implements ActionListener {

public void actionPerformed(ActionEvent e) {
double oneHunD = 27;
double twoFifD = 29;
double fiveHunD = 33;
double oneThouD = 41;
double twoThouD = 57;
//next day choice
if (e.getSource() == twoDB) {
if (bCQty.getSelectedItem() == "100") {
deliv = oneHunD;
} else if (bCQty.getSelectedItem() == "250") {
deliv = twoFifD;
} else if (bCQty.getSelectedItem() == "500") {
deliv = fiveHunD;
} else if (bCQty.getSelectedItem() == "1000") {
deliv = oneThouD;
} else if (bCQty.getSelectedItem() == "2000") {
deliv = twoThouD;
}
}
/*
Put here the other choices (seven day and up to two week.
*/

updateResult();
}
}

private void updateResult() {
double totale = quantitePrice + deliv + sidePrice /*+ design*/;
bCTotal.setText(String.valueOf(totale));
}

public static void main(String[] args) {
BCard bCard = new BCard();

}
}``````

Hope it hepls.

@moutanna

The lack of oop just made me cry

Sorry but the guy is asking for help on his code and "AS HE IS".