Results 1 to 2 of 2
  1. #1
    Chris Brines is offline Member
    Join Date
    Nov 2012
    Location
    California
    Posts
    2
    Rep Power
    0

    Default Questions about GUI Application

    Hello, I am new to this forum, and am not 100% sure how it works, but I'll type into here the problem I am trying to work, the code I have already, the questions I have will be in bold.

    Here's the problem:

    A long distance provider charges the following rates and charges for parts and for labor ($20 per hour).

    Rate Cagegory Rate Per Minute
    ----------------------------------------------------------------------
    Daytime (6am-5:59pm) $0.07 /*1st Question, is there a method I need to declare to tell time? I don't remember
    Evening (6pm - 11:59pm) $0.12 hearing of one */
    Off-Peak (12am - 5:59pm) $0.05

    Create a GUI application that allows the user to select a rate category (from a set of radio buttons), and enter the number of minutes of the call into a text field. A dialogue box should display.

    I created 3 classes. Instructions tell me to create 3 classes, declaring each thing in parentheses, in the corresponding class:

    1. CallPanel (declare text field, constructor, getCharges method)
    2. RatePanel (declare constants, radio buttons, constructor getRate method (to return chosen rate)
    3. Demo_Charges (Declare both panels, all buttons, constructor, build panel method, inner classes for calculating charges)



    Here is the code I have so far, with the names of the classes highlighted in bolded red

    CallPanel Class

    // Brines, Chris

    public class CallPanel

    {
    public static void main(String[]args)
    {
    new Demo_Charges();
    }
    }




    RatePanel Class

    // Brines, Chris

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

    public class RateCPanel extends JPanel
    {

    private final double DAY_TIME = 0.07;
    private final double EVENING = 0.12;
    private final double OFF_PEAK = 0.05;

    private JRadioButton dayTime;
    private JRadioButton evening;
    private JRadioButton offPeak;

    private ButtonGroup bg;

    public RateCategoryPanel()
    {

    setLayout(new GridLayout(4,1));

    dayTime = new JRadioButton("Daytime");
    evening = new JRadioButton("Evening");
    offPeak = new JRadioButton("Off Peak");

    bg = new ButtonGroup();
    bg.add(dayTime);
    bg.add(evening);
    bg.add(offPeak);

    setBorder(BorderFactory.createTitledBorder("Select a Rate Category"));

    add(dayTime);
    add(evening);
    add(offPeak);
    }

    public double getRate()
    {
    double rate = 0.0;

    if (dayTime.isSelected())
    rate = DAY_TIME;
    else if (evening.isSelected())
    rate = EVENING;
    else if (offPeak.isSelected())
    rate = OFF_PEAK;

    return rate;
    }

    }



    Demo_Charges Class

    // Brines, Chris




    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.DecimalFormat;



    public class Demo_Charges extends JFrame

    {
    // need another private final double here?

    private RatePanel panelr;
    private CallPanel panelc;

    private JPanel buttonPanel;
    private JButton calcButton;
    private JButton exitButton;

    public Demo_LongDistanceCharges()
    {
    super("Long Distance Charges");

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setLayout(new BorderLayout());


    panelr = new RatePanel(); /*I am getting errors here that say RatePanel can not be resolved to a type.
    panelc = new CallPanel(); I am using an example from my textbook that declares them just like this
    to reference custom panel objects */
    buildButtonPanel();


    add(panelr, BorderLayout.NORTH); /*Same error here*/
    add(panelc, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);

    pack();
    setVisible(true);
    }

    private void buildButtonPanel()
    {

    buttonPanel = new JPanel();

    calcButton = new JButton("Calculate Charges");
    exitButton = new JButton("Exit");


    calcButton.addActionListener(new CalcButtonListener());
    exitButton.addActionListener(new ExitButtonListener());


    buttonPanel.add(calcButton);
    buttonPanel.add(exitButton);

    }

    private class CalcButtonListener implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {

    // Do I need to add doubles to calculate total?


    // calculate charges

    // calculate total /*The code in bold to the left represents parts of this program I am stumped
    on as to what to do next */
    DecimalFormat dollar = new DecimalFormat("0.00");

    //Display Charges

    //JOptionPane.showMessageDialog
    }
    }

    private class ExitButtonListener implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {

    System.exit(0);
    }
    }
    }

    I am using an example of a program that makes a panel for a coffee shop, to calculate totals for customers, based on what they ordered. With a set price for each item, and a sales tax rate. To be calculated based on the buttons pushed, which represent the items ordered at the shop.

    This problem is asking me to calculate long distance rates based on the time of day the person uses the phone.

    I am fairly new to programming and the parts of the program that actually do the calculations, sometimes confuse me a bit. And I am not sure how to write into the program a method that will determine if the customer is to be charged with day, night, or off peak rates. But Besides that, the only question I have is about the error I am receiving that is mentioned above in bold.

    As far as I know, I have the RatePanel and CallPanel classes written correctly. But if someone could please take a look through my code and give me any advice, it would help tremendously.

    Thanks.

    EDIT: I am writing this in Eclipse Juno
    Last edited by Chris Brines; 11-15-2012 at 10:45 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,302
    Rep Power
    20

    Default Re: Questions about GUI Application

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. java application/some questions
    By batia in forum Advanced Java
    Replies: 0
    Last Post: 04-10-2012, 03:38 PM
  2. Replies: 3
    Last Post: 12-05-2010, 04:43 PM
  3. Replies: 3
    Last Post: 12-04-2009, 12:10 PM
  4. Replies: 1
    Last Post: 08-05-2009, 02:43 AM
  5. Replies: 0
    Last Post: 02-16-2008, 09:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •