0

I need some help with understanding an error that I am getting. Can anyone help me. Here is my problem. I am trying to hardcode information for a mortgage calc and I am getting an illegal start of expression error. Here is an example:

MortgageLoanCalculator.java:15: illegal start of expression
double interestRate = 5.7%; // Interest Rate = 5.75%

What does it mean?

5
Contributors
7
Replies
9
Views
12 Years
Discussion Span
Last Post by masijade
0

Can you post the previous few lines of the code ... the problem could be in the previous lines too ... look at them.

0

Sure. Here is the program.

public class MortgageLoanCalculator
{
    //Main method
        public static void main(String [] args)
    {
        double interestRate = 5.7%;                     int numberOfYears = 30;                      
                 double loanAmount = %200,00;                   

    //Enter monthly interest rate
    System.out.println("The interest rate is:" + interestRate);
    System.out.println("The loan amount is:"  + loanAmount);
    System.out.println("The term in years is:" + numberOfYears);

    }
}

Edited by pyTony: fixed formating

0

you might want to play around with the DecimalFormat class some, if you want your numbers to have commas after every three numbers and an % before or after your numbers.

0

Try this out now

public class MortgageLoanCalculator
{
//Main method
public static void main(String [] args)
{
double interestRate = 5.7; // you are defining a double value .. and % is not a double.
int numberOfYears = 30;
double loanAmount = 20000; //java doesnt recognize comas in doubles.

//Enter monthly interest rate
System.out.println("The interest rate is:" + interestRate);
System.out.println("The loan amount is:" + loanAmount);
System.out.println("The term in years is:" + numberOfYears);

}
}
0
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Priority extends JFrame{
	private JLabel processL[]=new JLabel[5];
	private JTextField ATtf[]=new JTextField[5];
	private JTextField BTtf[]=new JTextField[5];
	private JTextField ptf[]=new JTextField[5];
	private JButton priorB;
	private JButton cleaerB;
	private ActionListener al1,al2;
	private int at[]=new int[5];
	private int bt[]=new int[5];
	private int p=new int[5];
	public Priority(){
		super("Priority");
		setSize(240,240);
		setDefaultCloseOpertion(EXIT_ON_CLOSE);
		Container c=getContentPane();
		JPanel pane1=new JPanel();
		pane1.setLayout(new GridLayout(6,4));
		pane1.add(new JLabel("Process"));
		pane1.add(new JLabel("AT",SwingConstants.CENTER));
		pane.add(new JLabel("BT",SwingConstants.CENTER));
		pane1.add(new JLabel("P",SwingConstants.CENTER));
		for(int i=0;i<5;i++){
			processL[i]=new JLabel();
			ATtf[i]=new JTextField(6);
			BTtf[i]=new JTextField(6);
			ptf[i]=new JTextField(6);
		}
		process[0]=new JLabel("A",SwingConstants.CENTER);
		process[1]=new JLabel("B",SwingConstants.CENTER);
		process[2]=new JLabel("C",SwingConstants.CENTER);
		process[3]=new JLabel("D",SwingConstants.CENTER);
		process[4]=new JLabel("E",SwingConstants.CENTER);
		for(int i=0;i<5;i++){
			pane1.add(process[i]);
			pane1.add(ATtf[i]);
			pane1.add(BTtf[i]);
			pane1.add(ptf[i]);
		}
		JPanel pane2=new JPanel();
		pane2.setLayout(new GridLayout(1,2));
		priorB=new JButton("Priority");
		pane2.add(priorB);
		clearB=new JButton("Clear");
		pane2.add(clearB);
		c.setLayout(new GridBagLayout());
		GridBagConstraints gbc=new GridBagConstraints();
		gbc.gridx=0;
		gbc.gridy=0;
		c.add(pane1,gbc);
		gbc.gridx=0;
		gbc.gridy=1;
		c.add(pane2,gbc);
		pack();
		al1=new ActionListener(){
			public void actionPerformed(ActionEvent e){
				sked();
			}
		};
		al2=new ActionListener(){
			public void actionPerformed(ActionEvent e){
				for(int i=0;i<5;i++);
				ATtf[i].setText("");
				BTtf[i].setText("");
				ptf.setText("");
			}
		};
		priorB.addActionListener(al1);
	clearB.addActionListener(al2);
	}
	public void sked(){
	String str="T CPU Q\n";
	for(int i=0;i<5;i++){
		at[i]=Integer.parseInt(ATtf[i].getText());
		bt[i]=Integer.parseInt(BTtf[i].getText());
		p[i]=Integer.parseInt(ptf[i].getText());
	}
	int time=at[0]==0?0:1;
	for(;bt[0]>0;bt[0]--){
		str+=time+""+processL[0].getText()+" "+que(time,processL[0].getText())+"\n";
		time++;
	}
	int ar[]=new int[4];
	for(int i=1;i<5;i++)
	ar[i-1]=p[i];
	sort(ar);
	for(int i=0;i<4;i++){
		for(int j=1;j<5;j++){
			if(ar[i]==p[j]){
				ar[i]=j;
			}
		}
	}
	for(int i=0;i<4;i++){
		for(;bt[ar[i]]>0;bt[ar[i]]--){
			str+=time+""+processL[ar[i]].getText()+" "+que(time,processL[ar[i]].getText())+"\n";
			time++;
		}
	}
	System.out.println(str);
}
public String que(int time,String l){
	String str="";
	str+=queB(time,l)+queC(time,l)+queD(time,l)+queE(time,l);
	return str;
}
public String queE(int time,String l){
	if(time>=at[4]&&bt[4]>0&&!|.equals("4"))
	return "E";
	return "";
}
public String queB(int time,String l){
	if(time>=at[1]&&bt[1]>0&&!|.equals("B"))
	return "B";
	return "";
}
public String queC(int time,String l){
	if(time>=at[2]&&bt[2]>0&&!|.equals("C"))
	return "C";
	return "";
}
public String queD(int time,String l){
	if(time>=at[3]&&bt[3]>0&&!|.equals("D"))
	return "D";
	return "";
}
public void sort(int[] ar){
	int temp=0;
	for(int c=0;c<ar.length;c++){
		for(int i=0;i<ar.lenth-1-c;i++){
			if(ar[i]>ar[i+1]){
				temp=ar[i];
				ar[i]=ar[i+1];
				ar[i+1]=temp;
			}
		}
	}
}
public static void main(String[] args){
	(new Priority()).setVisible(true);
}
	
}

please help me with this, I'm sicked and tired to find out where my error is, it says ";" expected and illegal start of expression.tnx

Edited by masijade: code tags added

0

Start your own thread, do not hijack someone else's. Locking this thread now, as it is 6 years dead, anyhow.

Edited by masijade: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.