DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Posts
    2

    Question need clarification on code

    Can someone tell me if this code will compile? The code compiles and runs for me with NetBeans, so I cannot figure out why someone would tell me the code does not compile. I know that when I made the change to all class statements within the code, I left one line still referring to mortgagecalc, but the class was main. Thanks!!
    Code:
      /*
      	Week 2: Loan Calculator with GUI
      	Programmer: Harold Peterson
        Date: March 29, 2010
      	Filename: Main.java
      	Purpose: This project will calculate the user-entered monthly loan payment.
      		     The user will enter the loan amount, term, and interest rate
                 entered and the loan payment should be displayed.
    */
    
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    //Create tabs, buttons, and fields
    public class Main extends JFrame implements ActionListener {
    private JPanel panelAdder;
    private JLabel labelamt;
    private JLabel labelterm;
    private JLabel labelrate;
    private JTextField textFieldAmount;
    private JTextField textFieldTerm;
    private JTextField textFieldRate;
    private JTextField textFieldResult;
    private JButton buttonCalc;
    
    public Main() {
      initComponents();
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
      pack();
    
      //Create ActionListeners
      buttonCalc.addActionListener(this);
    }
    
    public void initComponents() {
     //Initializing components
     panelAdder = new JPanel();
     labelamt = new JLabel("Amount");
     textFieldAmount = new JTextField();
     labelterm = new JLabel("Term");
     textFieldTerm = new JTextField();
     labelrate = new JLabel("Rate");
     textFieldRate = new JTextField();
     textFieldResult = new JTextField();
     buttonCalc = new JButton("Calculate");
    
     //Setting the object attributes
     textFieldResult.setEditable(false);
     textFieldResult.setColumns(8);
     textFieldAmount.setColumns(6);
     textFieldTerm.setColumns(2);
     textFieldRate.setColumns(2);
    
     Container contentPane = getContentPane();
     contentPane.setLayout(new FlowLayout());
    
     //Adding the components to the panel
     panelAdder.add(labelamt);
     panelAdder.add(textFieldAmount);
     panelAdder.add(labelterm);
     panelAdder.add(textFieldTerm);
     panelAdder.add(labelrate);
     panelAdder.add(textFieldRate);
     panelAdder.add(buttonCalc);
     panelAdder.add(textFieldResult);
    
     contentPane.add(panelAdder);
    }
    
    public static void main(String[] args) {
      MortgageCalc frame = new MortgageCalc();
    }
    
    private void setResultValue() {
       double amount = Double.parseDouble(textFieldAmount.getText());
       double term = Integer.parseInt(textFieldTerm.getText());
       double rate = Double.parseDouble(textFieldRate.getText()) / 100.;
       double result = (amount * Math.pow((1 + (rate/12)),term) * (rate/12)) / (Math.pow((1 + (rate/12)),term) - 1);
    
       textFieldResult.setText(Double.toString(result));
    }
    
    public void actionPerformed(ActionEvent event) {
      System.out.println("Action Button");
      String command = event.getActionCommand();
      if ("Calculate".equals(command)) {
          setResultValue();
      }
    }
    }

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Quote Originally Posted by javastarter View Post
    so I cannot figure out why someone would tell me the code does not compile.
    Why wouldn't it compile for this person?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Apr 2010
    Posts
    2
    The person in question is my instructor and he has given several different reasons, which I have proven to be inaccurate. I just wanted to know if the code compiles for someone that is considered to be advanced in Java. Can you tell me if you can compile and run the code? I know that the calculation is off, but the rest of the code works as it should. Thanks!

Similar Threads

  1. Jupitermedia Legal Notice -- NO PERMISSION TO USE CODE SAMPLES?!
    By Noryk Rekrap in forum Talk to the Editors
    Replies: 3
    Last Post: 08-23-2007, 03:56 PM
  2. .NET equals Efficiency
    By Kevin in forum .NET
    Replies: 150
    Last Post: 03-04-2002, 05:40 PM
  3. Another Language
    By Steven Bell in forum .NET
    Replies: 260
    Last Post: 06-01-2001, 04:32 PM
  4. Replies: 90
    Last Post: 04-17-2001, 12:45 AM
  5. error code in JSP(please chek the code)
    By satish in forum Java
    Replies: 1
    Last Post: 09-22-2000, 09:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links