2 Replies - 392 Views - Last Post: 14 May 2012 - 07:28 PM Rate Topic: -----

#1 reynante  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-May 12

why is it that this program wont show any output..?

Posted 14 May 2012 - 06:54 PM

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class finals extends Applet implements ActionListener,ItemListener{
	int a;
	Label iaLbl = new Label("Items Available:");   
	Checkbox friesBox = new Checkbox("Fries",false);
	Checkbox spagBox = new Checkbox("Spaghetti",false);
	Checkbox burgerBox = new Checkbox("Burger",false);
	Checkbox drinksBox = new Checkbox("Drinks",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 sizeLbl = new Label("Size");
	Choice fchoice = new Choice();
	Choice schoice = new Choice();
	Choice bchoice = new Choice();
	Choice dchoice = new Choice();

 	Label tpLbl = new Label("Total Price:");
	TextField tp1Txt = new TextField(10);
	TextField tp2Txt = new TextField(10);
	TextField tp3Txt = new TextField(10);
	TextField tp4Txt = new TextField(10);

    Label tocLbl = new Label("Type of Customer:");
	CheckboxGroup optGroup = new CheckboxGroup();
	Checkbox member = new Checkbox("Member(10% Discount)",false,optGroup);
	Checkbox student = new Checkbox("Student(5% Discount)",false,optGroup);
	Checkbox senior = new Checkbox("Senior Citizen(20% Discount)",false,optGroup);
	Checkbox others = new Checkbox("Others",false,optGroup);

 	Label tiLbl = new Label("Total Items:");
 	TextField tiTxt = new TextField(10);
	Label taLbl = new Label("Total Amount:");
	TextField taTxt = new TextField(10);

	Label disLbl = new Label("Discount:");
	TextField disTxt = new TextField(10);

 	Label atpLbl = new Label("Amount to Pay:");
	TextField atpTxt = new TextField(10);

 	Label arLbl = new Label("Amount Received:");
	TextField arTxt = new TextField(10);
	Label changeLbl = new Label("Change:");
	TextField changeTxt = new TextField(10);
	Button compButton = new Button("COMPUTE");
	Button resetButton = new Button("RESET");

 	Button payButton = new Button("PAY");
	int ti,ta,qty1,qty2,qty3,qty4,tp1=0,tp2=0,tp3=0,tp4=0,s1=40,f1=0,f2=0,b1=0,b2=0,d1=0,d2=0,d3=0;
	double dis=0,atp=0,change=0,ar=0;

public void init()
    {
  	setLayout(new GridLayout(8,7));
  	add(iaLbl);
  	add(friesBox);
  	friesBox.addItemListener(this);
  	add(spagBox);
  	spagBox.addItemListener(this);
  	add(burgerBox);
  	burgerBox.addItemListener(this);
  	add(drinksBox);
  	drinksBox.addItemListener(this);
  	add(qtyLbl);
  	add(qty1Txt);  
  	add(qty2Txt);
  	add(qty3Txt);
  	add(qty4Txt);
  	add(sizeLbl);
  	add(fchoice);
  	fchoice.addItem("Regular P 30");
  	fchoice.addItem("Large P 40");
  	add(schoice);
    schoice.addItem("P 40");
    add(bchoice);
    bchoice.addItem("Regular P 30");
    bchoice.addItem("With Cheese P 35");
    add(dchoice);
    dchoice.addItem("Regular P 15");
    dchoice.addItem("Medium P 20");
    dchoice.addItem("Large P 25");

	add(tpLbl);
	add(tp1Txt);   
	add(tp2Txt);
	add(tp3Txt);
	add(tp4Txt);
	add(tocLbl);  
	add(member);
	member.addItemListener(this);
	add(student);
	student.addItemListener(this);
	add(senior);
	senior.addItemListener(this);
	add(others);
	others.addItemListener(this);
	
	add(tiLbl);
	add(tiTxt);
	add(taLbl);
	add(taTxt);
	add(disLbl);
	add(disTxt);
	add(atpLbl);
	add(atpTxt);
	add(arLbl);
	add(arTxt);
	add(changeLbl);
	add(changeTxt);
	add(compButton);
	compButton.addActionListener(this);
	add(resetButton);
	resetButton.addActionListener(this);   
		add(payButton);
		payButton.addActionListener(this);   
}
public void itemStateChanged(ItemEvent e){

if(member.getState())
    a=1;
    else if(student.getState())
       a=2;
       else if(senior.getState())
       	a=3;
       	else if(others.getState())
       		a=4;
       		}

 public void actionPerformed(ActionEvent e){
 	String arg;
	arg=e.getActionCommand();  
		if(e.getSource()==compButton)
			{
				if(friesBox.getState())
					{
						qty1=Integer.parseInt(qty1Txt.getText());
					f1=30;
				tp1=qty1*f1;
			tp1Txt.setText("" +tp1);
		}
else
	{
       qty1=Integer.parseInt(qty1Txt.getText());
       f2=40;
        tp1=qty1*f2;
             tp1Txt.setText("" +tp1);
             }
             if(spagBox.getState())
             	{
             		qty2=Integer.parseInt(qty2Txt.getText());  
             			tp2=qty2*s1;
             			tp2Txt.setText("" +tp2);
             			}
else
	{
    qty2=Integer.parseInt(qty2Txt.getText());
     s1=0;  
      tp2=qty2*s1;
       tp2Txt.setText("" +tp2);
        }
         if(burgerBox.getState())
          {
          qty3=Integer.parseInt(qty3Txt.getText());
          b1=30;
          tp3=qty3*b1;
          tp3Txt.setText("" +tp3);
           }
else
    {
     qty3=Integer.parseInt(qty3Txt.getText());
      b2=35;
      tp3=qty3*b2;
       tp3Txt.setText("" +tp1);
         }
             if(drinksBox.getState())
               {
               	qty4=Integer.parseInt(qty4Txt.getText());
               	 d1=15;
               	  tp4=qty3*d1;
               	   tp4Txt.setText("" +tp4);  
               	   	 }
               	 else if(drinksBox.getState())
               	 {
            	qty4=Integer.parseInt(qty4Txt.getText());
              d2=20;
             tp4=qty4*d2;
            tp4Txt.setText("" +tp4);
           }
 
else if(drinksBox.getState())
     {
      qty4=Integer.parseInt(qty4Txt.getText());
       d3=25;
        tp4=qty4*d3;
         tp4Txt.setText("" +tp4);
          }
            if(a==1)
             {
             ti=(qty1) + (qty2) + (qty3) + (qty4);
             tiTxt.setText(""+ti);
             ta=(tp1) + (tp2) + (tp3) + (tp4);
             taTxt.setText(""+ta);
             dis=ta * 0.1;
             disTxt.setText(""+dis);
             atp=ta;
             atpTxt.setText(""+atp);
             }
else if(a==2)
   {
   	  ti=(qty1) + (qty2) + (qty3) + (qty4);
   	    tiTxt.setText(""+ti);
   	     ta=(tp1) + (tp2) + (tp3) + (tp4);
   	      taTxt.setText(""+ta);
   	       dis=ta * 0.05;
   	        disTxt.setText(""+dis);
   	         atp=ta;
   	          atpTxt.setText(""+atp);
   	           }
       else if(a==3)
       	     {
       	     	 ti=(qty1) + (qty2) + (qty3) + (qty4);
       	     	  tiTxt.setText(""+ti);
       	     	   ta=(tp1) + (tp2) + (tp3) + (tp4);
       	     	    taTxt.setText(""+ta);
       	     	     dis=ta * 0.2;
       	     	      disTxt.setText(""+dis);
       	     	       atp=ta;
       	     	        atpTxt.setText(""+atp);
       	     	         }
       	     	        else if(a==4)
       	     	        {
       	     	       ti=(qty1) + (qty2) + (qty3) + (qty4);
       	     	      tiTxt.setText(""+ti);
       	     	     ta=(tp1) + (tp2) + (tp3) + (tp4);
       	     	    taTxt.setText(""+ta);
       	     	   disTxt.setText("" +dis);
       	     	 atp=ta;
       	       atpTxt.setText(""+atp);
       	      }
       	     repaint();
       	    }
else if(e.getSource()==resetButton)
    {
     friesBox.setState(false);
      spagBox.setState(false);
       burgerBox.setState(false);
        drinksBox.setState(false);
         qty1Txt.setText("");
          qty2Txt.setText("");
           qty3Txt.setText("");
            qty4Txt.setText("");
             fchoice.select(0);
              bchoice.select(0);
               dchoice.select(0);
                tp1Txt.setText("");
                 tp2Txt.setText("");
                  tp3Txt.setText("");
                   tp4Txt.setText("");
                    member.setState(false);
                     student.setState(false);
                      senior.setState(false);
                       others.setState(false);
                        tiTxt.setText("");
                       taTxt.setText("");
                      disTxt.setText("");
                    atpTxt.setText("");
                  arTxt.setText("");
                 changeTxt.setText("");
               a=1;
                ti=0;
                 ta=0;
                  dis=0;
                 qty1=0;
                qty2=0;
               qty3=0;
                qty4=0;
                 tp1=0;
                  tp2=0;
                 tp3=0;
                tp4=0;
               repaint();
              }

else if(e.getSource()==payButton)
   {
     ar=Integer.parseInt(arTxt.getText());
      change=ar-atp;
       changeTxt.setText("" +change);
        }
         repaint();
          }
          }



*Edited: added code tags. Please :code:

This post has been edited by pbl: 14 May 2012 - 07:22 PM


Is This A Good Question/Topic? 0
  • +

Replies To: why is it that this program wont show any output..?

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,361
  • Joined: 02-June 10

Re: why is it that this program wont show any output..?

Posted 14 May 2012 - 07:03 PM

What part of
:code:
Do you not understand?

Attached Image

What do you define as "output"? Is there a label or textbox that should be receiving something? You need to do something to help us out at least a little: We're not in your head to know what you're thinking or on your screen to see this.

Have you done any debugging? Do you understand breakpoints and walking through your code?

reynante: What this shows us is that you aren't familiar with breakpoints and how to debug your own code. Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


See FAQ # 2. (Click the SHOW button below)


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Apr 2012
Spoiler



Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: why is it that this program wont show any output..?

Posted 14 May 2012 - 07:28 PM

Please put your question in the post body not in the topic title it may be truncated.

What do you mean "does not show any output" ?

And you should seriously consider learning how to use array before writing such an application
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1