GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Oct-2005, 15:53
123awd 123awd is offline
New Member
 
Join Date: Oct 2005
Posts: 4
123awd is on a distinguished road

i really need help in coding this applet.. i gave up !! plz help


can any1 help me in coding this following applet question:

(ASAP)

Write a windowed application to fulfill the following requirements. This applet will be built upon the topics we have studied in lectures: Java Applications, Methods, Classes Arrays, AWT Components plus methods in the Java Math class, e.g., square root, compound interest, etc.
User interface:

•Your program should prompt the user to enter the price of a house, the number of years for which they would like to make payments towards re-paying the mortgage for the house, the interest rate charged for mortgage, and the down-payment amount.

•Your program should use check-buttons to allow the user to select one of two types of loans – the SIMPLE INTEREST LOAN or the COMPOUND INTEREST LOAN

•Your program should then use all the information provided in the above two bullet-points to calculate the following:

1.Total amount the borrower will pay at the end of the borrowing period – in Dirham

2.Monthly loan payment amount in Dirham

3.Amount to be saved if complete loan is paid in half the re-payment period indicated by borrower.
4.Amount to be saved if complete loan is paid in ¾ of the time indicated by the borrower.

•The above four pieces f information should be displayed as labels inside a results panel. The results panel should not overlap the data-input panel but both panels should be included in the same window.
Technical requirements:
Your program should perform the following.
1.Obtain user inputs using AWT components.

2.Create two separate classes to determine the simple interest loan’s results, and the compound interest loan’s results

3.Group all outputs into the same CLASS. This class should be different from the one in which user inputs are captured.
  #2  
Old 09-Oct-2005, 21:57
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: i really need help in coding this applet.. i gave up !! plz help


hi 123awd,

Welcome to the GIDForums.

You should create two separate classes as you said for your simple interest and compound interest.

How would you create a simple interest class?
Create four variables for price, rate of interest, years and the downpayment.
Create three methods. One to get the inputs(you can use the constructor fo this), one to print or return the output and one to calculate the simple interest.

Do the same for your compound interest class.

Use two different files for simple and compound interest classes.

The third class is the applet class where you use the objects of simple and compound interest.
Lets start with applets.
How to create awt components and use them?
import java.awt.*; for using the awt components.

The AWT supplies the following UI components:
# Buttons (java.awt.Button)
# Checkboxes (java.awt.Checkbox)
# Single-line text fields (java.awt.TextField)
# Larger text display and editing areas (java.awt.TextArea)
# Labels (java.awt.Label)
# Lists (java.awt.List)
# Pop-up lists of choices (java.awt.Choice)
# Sliders and scrollbars (java.awt.Scrollbar)
# Drawing areas (java.awt.Canvas)
# Menus (java.awt.Menu, java.awt.MenuItem, java.awt.CheckboxMenuItem)
# Containers (java.awt.Panel, java.awt.Window and its subclasses)
(extracted from java.sun.com)

So to use a container, simply create an instance of it.
For example, to create a TextField, you can create new member variable of the class:
Textfield input;

Then in your init() in the applet(You can find more information about applet Applets, you can enter this:
input=new TextField();

Create a new layout. Use a simple Grid Layout(You know layouts dont you?)
If you dont know about layouts, check this link:Layouts
setLayout(new GridLayout(x,y));
where you should replace x and y according to the number of components you are displaying.

Then add the text field to the applet.
add(field);
validate();
Invoking validate once after adding one or more Components to an applet ensures that the Components draw themselves onscreen.

you dont have to put like java.awt.TextField because you have already imported java.awt.*;
Similarly you can use the various components available.

You can use ActionListener to check whether the user had clicked a button or many other user actions.
The various user actions are:

action() (Event.ACTION_EVENT)
mouseEnter() (Event.MOUSE_ENTER)
mouseExit() (Event.MOUSE_EXIT)
mouseMove() (Event.MOUSE_MOVE)
mouseDown() (Event.MOUSE_DOWN)
mouseDrag() (Event.MOUSE_DRAG)
mouseUp() (Event.MOUSE_UP)
keyDown() (Event.KEY_PRESS or Event.KEY_ACTION)
keyUp() (Event.KEY_RELEASE or Event.KEY_ACTION_RELEASE)
gotFocus() (Event.GOT_FOCUS)
lostFocus() (Event.LOST_FOCUS)
handleEvent() (all event types)

Create action commands for the inputs so that you can identify the action:
setActionCommand("enable");

Then create instances of the simple and compound interest classes.

Here is the main program:
JAVA Code:
import java.applet.Applet;
import java.awt.*;

public class interest extends Applet implements implements ActionListener
{    

    simple sim;                           //simple is the simple interest class
    compound com;                    //compound is the compound interest class.

   TextField price, roi, years, down_payment;  //use four textfields for input
   Checkbox simp,comp;                                      //one check box for simple or compound
   Button  submit, reset;                           //two buttons  
Label y,r,p,d;                                         //display labels for information

    public void init()
    {

//create instances of labels here

    price = new TextField("0",10);
    roi = new TextField("0",10);
    years = new TextField("0",10);
    down_payment = new TextField("0",10);
    submit=new Button("Submit");
    cancel=new Button("reset");
    simp=new CheckBox("Simple Interest",true);
    comp=new CheckBox("Compound Interest");
     
    submit.setActionCommand("submit");
    submit.addActionListener(this);

    reset.setActionCommand("reset");
    reset.addActionListener(this);


        //Use a GridLayout with 2 columns and any number of rows
        //and 5 pixels of padding around all edges of each cell.
        setLayout(new GridLayout(0,2,5,5));    

        //add all the components to the applet in order

       validate();
}


    public void start()
    {

    }

    public void stop() 
    {

    }
    

    public void destroy() 
    {

    }

public void actionPerformed(ActionEvent e) 
{
if ("submit".equals(e.getActionCommand())) 
{
//add code here to display the interest
}

if ("reset".equals(e.getActionCommand())) 
{
//add code here to reset the fields
}   
}

}

I hope you understood what i have typed.

You can find about more information of all these in the sun java documentation.
Sun Java documentation

Regards,
Paramesh.

PS:
Some of the awt component tutorials are missing in the documentation.
They are available as download instead.
Here is the link for old awt documentation:
AWT
This is because programmers dont use awt nowadays.
They use JFC instead because they are lightweight components.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #3  
Old 28-Oct-2005, 06:48
123awd 123awd is offline
New Member
 
Join Date: Oct 2005
Posts: 4
123awd is on a distinguished road

Re: i really need help in coding this applet.. i gave up !! plz help


Hey man thanks alot for your help but the thing is that what is written here is so advanced and i dont understand 90% of whats written here and i really need this program to be working in max 2 days i really dont know what to do...so please help it is really important
Thanks man ...
  #4  
Old 28-Oct-2005, 10:14
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: i really need help in coding this applet.. i gave up !! plz help


Hi awd,

Quote:
Originally Posted by 123awd
the thing is that what is written here is so advanced and i dont understand 90% of whats written here

I replied that way because :

Quote:
Originally Posted by 123awd
This applet will be built upon the topics we have studied in lectures: Java Applications, Methods, Classes Arrays, AWT Components plus methods in the Java Math class, e.g., square root, compound interest, etc.

So, if you tell us what is your progress in this past 18 days, we could help you in a much efficient way.
You could also post your code so that we could modify it in a way you understand.

Best Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #5  
Old 28-Oct-2005, 16:44
123awd 123awd is offline
New Member
 
Join Date: Oct 2005
Posts: 4
123awd is on a distinguished road

Re: i really need help in coding this applet.. i gave up !! plz help


Hi Paramesh hope all is good:
I have done it the way we studied the material but the thing is that there are few parts that i didnt know how to do ....i will attach the java file i have done but the missing parts are
1.Check buttons for the simple and comp interest
2.cutting it into different classes (2.Create two separate classes to determine the simple interest loan’s results, and the compound interest loan’s results)
3.Group all outputs into the same CLASS. This class should be different from the one in which user inputs are captured i didnt evenunderstand this part.
I am really thankful and I really appreciate your help
another thing can you check the output,, it looks really weird when you use a large number of years for instance 7,8,9,10 the output isnt organized and i dont know how to format it,
Attached Files
File Type: zip MortCalc.zip (1.9 KB, 15 views)
  #6  
Old 28-Oct-2005, 23:56
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: i really need help in coding this applet.. i gave up !! plz help


Hi awd,

Here is a very quick reply:

You can add radiobuttons by:
JAVA Code:
JRadioButton simp,comp;
You should create a button group because at a time, only one should be selected.
JAVA Code:
            private ButtonGroup radioGroup;

Then we should initialize it in the createUserInterface() method like this:
JAVA Code:
       simp=new JRadioButton("Simple Interest",true);  //create two radio buttons
       comp=new JRadioButton("Compound Interest");
       
       radioGroup = new ButtonGroup(); //new group. add simp and comp to the group
       radioGroup.add( simp );
       radioGroup.add( comp ); 
The radio group should contain simp and comp.

Then we should create a itemlistener for the radio buttons.
This is done by creating a class RadioButtonHandler.
Before that, we should add the components to the contentPane.
like this:
JAVA Code:
   simp.setBounds(220,50,150,20);    //set bounds
   comp.setBounds(220,70,150,20);

   RadioButtonHandler handler = new RadioButtonHandler();

   simp.addItemListener( handler );   //add item listener
   comp.addItemListener( handler );

   contentPane.add(simp);             //add to the pane
   contentPane.add(comp);


The handler class is similar to your anonymous inner class.
its definition is like this:
JAVA Code:
   // private inner class for ItemListener event handling
   private class RadioButtonHandler implements ItemListener 
   {

        public void itemStateChanged( ItemEvent event )
        {
           if ( event.getSource() == simp )  //check whether simp is the source
           {
              if ( event.getStateChange() == ItemEvent.SELECTED )
              {
                   //add code here
              }
           }

           if ( event.getSource() == comp )  //check whether comp is the source
           {
              if ( event.getStateChange() == ItemEvent.SELECTED )
              {
                  //add code here
              }
           }
       }
   }
I think you can understand this bit.

Now to the simple and compound interest classes:
Create a new file simpleInterest.java(it should be in the same directory as MortCalc.java)
create a simpleInterest class like this:
JAVA Code:
class simpleInterest
{
      public int price, roi, downpayment, years;

      public float interest;

      public calculate( int fprice, int froi, int fdownpayment, int fyears)
      {
            //add code to calculate the simple interest here
      }
}

Similarly create one for compoundInterest.

Calculate the interest and other variables using the calculate method.
you should pass the corresponding parameters for the calculate function.

Then in the MortCalc, add the classes like this:
JAVA Code:
simpleInterest sim;
compoundInterest com;


You can modify your calculateJButtonActionPerformed like this:
1. check if simpleinterest radiobutton is selected. If it is selected, then calculate the simple interest by calling the method sim.calculate(..)
2. If compoundinterest is selected, do the same way.

So if it is simple, display the answer by using the simple class members.
i.e simple.interest will give you the interest. simple.price will give you the price and so on.

This is a very quick reply because i am going out now(be back in 3 hrs). Just to give you some information.

Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #7  
Old 29-Oct-2005, 09:07
123awd 123awd is offline
New Member
 
Join Date: Oct 2005
Posts: 4
123awd is on a distinguished road

Re: i really need help in coding this applet.. i gave up !! plz help


Hey Mr. Paramesh:
I would like to thank you for your help and for your fast replies....i tried to use the code above in my program and it didnt work... So it would be really great if it was added into my Java file that i have posted... This assignment is due tomorow and its really important and weights alot towards my final grade...I appreciate your understanding... thanks again.....
AWD
  #8  
Old 02-Nov-2005, 03:33
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: i really need help in coding this applet.. i gave up !! plz help


Hi awd,

Hope your assignment submission went well.
Sorry, I was not able to reply because i went to my hometown.

If you still have any doubts, post again to clarify.

Best Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with Simple 1D Array coding project rho C++ Forum 2 27-Jun-2005 19:05
need help with some c++ coding.. vivina C++ Forum 9 13-Dec-2004 23:58
PHP/MySQL coding issue cmarti MySQL / PHP Forum 3 26-Jul-2004 08:01
Pls help in this coding. harsha C++ Forum 5 08-Apr-2004 20:48
coding a word with a givin factor funnyf C++ Forum 2 13-Jan-2004 08:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:27.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.