Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2005

Tip: Looking for answers? Try searching our database.

No error messages but doesn't give the required output..

Thread view: 
kt - 07 Apr 2005 18:54 GMT
Hello folks,
I wrote the program below to calculate cost of phone call when the user
enters values for hours, minutes and seconds. I have to convert hours and
seconds to minutes so that i can calculate cost of phone call which is 10
cents per min. Code compiles without any errors but does not display the
output. Listed below is the code. I would greatly appreciate any help.
Thanx,
kt

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

public class Lab8a extends Applet
                  implements ActionListener
{
 private TextField hourTF, minTF, secTF, outputTF;
 private Button calculateButton, clearButton;
 private int hours, mins, secs, totalMin, totalCost;
 
public void init()
 {
    Label inputLbl, hrLbl, minLbl, secLbl, outputLbl;
    inputLbl  = new Label("Please enter an integer value only");
    outputLbl = new Label("The cost of phone call in cents:");
   
    hrLbl  = new Label("Hours:");
    minLbl = new Label("Minutes:");
    secLbl = new Label("Seconds:");
   
    hourTF   = new TextField(7);
    minTF    = new TextField(7);
    secTF    = new TextField(7);
    outputTF = new TextField(7);
   
    calculateButton = new Button("CALCULATE");
    clearButton     = new Button("CLEAR");
   
    add(inputLbl);
    add(hrLbl);
    add(hourTF);
    add(minLbl);
    add(minTF);
    add(secLbl);
    add(secTF);   
    add(calculateButton);
    add(clearButton);
    add(outputLbl);
    add(outputTF);
   
    hourTF.addActionListener(this);
    minTF.addActionListener(this);
    secTF.addActionListener(this);
    outputTF.addActionListener(this);
    clearButton.addActionListener(this);
    calculateButton.addActionListener(this);
     
 }
   
public void actionPerformed (ActionEvent event)
    {
     outputTF.setEditable(false);
    
            if(event.getSource() == calculateButton)
            {
             calculateTotal();
             outputTF.setText(Integer.toString(totalCost));
         }     
           
         if(event.getSource() == clearButton)
         outputTF.setText("");
         
       
    }
   
public int calculateTotal()   
 {
     totalMin  = hours * 60 + mins + secs / 60;
     totalCost = totalMin * 10;
     return totalCost;
    }

public void paint(Graphics g)
    {
       
                       
    }

}
Thomas Fritsch - 07 Apr 2005 19:14 GMT
kt via JavaKB.com schrieb:
> Hello folks,
> I wrote the program below to calculate cost of phone call when the user
[quoted text clipped - 73 lines]
>  public int calculateTotal()   
>   {
// Forgot to get the numbers from the TextFields into your variables:
        hours = ...;  // get it from hourTF
        mins  = ...;  // get it from minTF
        secs  = ...;  // get it from secTF
// The rest is left as an exercise to the reader ;-)

// By the way: It is not necessary to declare all these int's as member
// variables of your class. Local variables in this method would
// suffice.

>       totalMin  = hours * 60 + mins + secs / 60;
>       totalCost = totalMin * 10;
[quoted text clipped - 8 lines]
>
> }

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

kt - 08 Apr 2005 20:12 GMT
Fritsch,
          Thanx for taking your time to reply. I fixed the code.
kt


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.