4 Replies - 3257 Views - Last Post: 16 May 2011 - 07:07 PM Rate Topic: -----

#1 uptown_hound  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-May 11

Java Mortgage Payment Calculator W/ GUI / Chart

Posted 16 May 2011 - 03:26 PM

Good afternoon all! I am a beginning JAVA programmer in a intro to Java II class. I've seen numerous posts on this topic but I am stuck. The assignment is to Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans:

- 7 years at 5.35%
- 15 years at 5.5%
- 30 years at 5.75%

Use an array for the mortgage data for the different loans. Read the interest rates to fill the array from a sequential file. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Add graphics in the form of a chart.

The code compiles but will not run this is the message I get when I try to run the code:

No main methods, applets, MIDIets found in file.

 // Program draws a bar chart. 
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*; //for the class Rectangle2D
import javax.swing.*;
import java.applet.Applet;
import java.awt.Graphics;

class Chart extends JFrame 
{
   //to store the number of yeras	
   
   private int years;

   // constructor 
   public Chart( int years)
   {
//set title for the window
	  super( "Mortgage Payment Calculator Chart" );
	  
this.years = years ;
	  
	
	  // set the size of the window and let it be visible
	  setSize( 1000, 700 );
	  setVisible( true );
	
   }

   // Draw chart
   // The method 'paint' will be executed right away after the constructor.
   public void paint( Graphics g ) 
   {
	  super.paint( g );

	  // creates a 2D object to draw
	  Graphics2D g2d = ( Graphics2D )g;

	  // set color and draw the bar for the first quarter sales
	  g2d.setColor( Color.blue );
	  g2d.drawLine(110,30,110,655);	
	  g2d.drawLine(110,655,1015, 655);
        g2d.setFont( new Font("Font.PLAIN", Font.PLAIN , 18));
g2d.drawString("^", 7, 100);
g2d.drawString("|", 7, 110);
	  g2d.drawString("A", 10, 150);
g2d.drawString("M", 7, 170);
g2d.drawString("O", 7, 190);
g2d.drawString("U", 7, 210);
g2d.drawString("N", 7, 230);
g2d.drawString("T", 7, 250);

int amount = 200000;
int line = 55 ;
for(int i=0; i< 660; i+=60)
{

g2d.drawString("$"+ amount, 30, 60+i);
g2d.drawLine(105,line+i ,115,line+i);

amount =  amount- 20000;

}
g2d.drawString("Y E A R S ------>", 500, 690);

if(years == 30)
{
int count =0;
for(int i=0; i<= 990; i+=30)
{
g2d.drawString(""+count , 107+i, 675);
g2d.drawLine(110+i,650,110+i,660);
count++;
}
g2d.setColor( Color.red );

g2d.drawLine(110,30,1010,655);
}
else
if(years == 20)
{
int count =0;
for(int i=0; i<= 990; i+=45)
{
g2d.drawString(""+count , 107+i, 675);
g2d.drawLine(110+i,650,110+i,660);
count++;
}
g2d.setColor( Color.red );

g2d.drawLine(110,55,1010,655);
}
else
if(years == 15)
{
int count =0;
for(int i=0; i<= 990; i+=60)
{
g2d.drawString(""+count , 107+i, 675);
g2d.drawLine(110+i,650,110+i,660);
count++;
}
g2d.setColor( Color.red );

g2d.drawLine(110,55,1010,655);
}
else
if(years == 10)
{
int count =0;
for(int i=0; i<= 990; i+=90)
{
g2d.drawString(""+count , 107+i, 675);
g2d.drawLine(110+i,650,110+i,660);
count++;
}
g2d.setColor( Color.red );

g2d.drawLine(110,55,1010,655);
}
else
if(years == 7)
{
int count =0;
for(int i=0; i<= 990; i+=120)
{
g2d.drawString(""+count , 107+i, 675);
g2d.drawLine(110+i,650,110+i,660);
count++;
}
g2d.setColor( Color.red );

g2d.drawLine(110,55,950,655);
}

g2d.setFont( new Font("Font.BOLD", Font.PLAIN , 24));
g2d.drawString("Mortgage Payment Calculator Chart", 300, 50);

}

} 


Is This A Good Question/Topic? 0
  • +

Replies To: Java Mortgage Payment Calculator W/ GUI / Chart

#2 Renagado  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 118
  • View blog
  • Posts: 388
  • Joined: 14-June 09

Re: Java Mortgage Payment Calculator W/ GUI / Chart

Posted 16 May 2011 - 03:28 PM

There is no main method in this class. Every program needs a main method, if it doesn't, where will it start running?
Was This Post Helpful? 0
  • +
  • -

#3 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 203
  • View blog
  • Posts: 1,731
  • Joined: 13-March 10

Re: Java Mortgage Payment Calculator W/ GUI / Chart

Posted 16 May 2011 - 03:29 PM

Oh man... The world has invented JLabel !! :). Check it out.
Was This Post Helpful? 1
  • +
  • -

#4 Renagado  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 118
  • View blog
  • Posts: 388
  • Joined: 14-June 09

Re: Java Mortgage Payment Calculator W/ GUI / Chart

Posted 16 May 2011 - 03:32 PM

View Postdarek9576, on 17 May 2011 - 12:29 AM, said:

Oh man... The world has invented JLabel !! :). Check it out.

lol, you got a point there. convenient little things they are
Was This Post Helpful? 0
  • +
  • -

#5 vienhuynh  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 123
  • Joined: 24-April 10

Re: Java Mortgage Payment Calculator W/ GUI / Chart

Posted 16 May 2011 - 07:07 PM

No main method, that why you receive such errors
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1