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?

## All 7 Replies

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

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);

}
}
``````

The % is a sign for modular division in java.

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.

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);

}
}``````
``````import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Priority extends JFrame{
private JLabel processL[]=new JLabel;
private JTextField ATtf[]=new JTextField;
private JTextField BTtf[]=new JTextField;
private JTextField ptf[]=new JTextField;
private JButton priorB;
private JButton cleaerB;
private ActionListener al1,al2;
private int at[]=new int;
private int bt[]=new int;
private int p=new int;
public Priority(){
super("Priority");
setSize(240,240);
setDefaultCloseOpertion(EXIT_ON_CLOSE);
Container c=getContentPane();
JPanel pane1=new JPanel();
pane1.setLayout(new GridLayout(6,4));
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=new JLabel("A",SwingConstants.CENTER);
process=new JLabel("B",SwingConstants.CENTER);
process=new JLabel("C",SwingConstants.CENTER);
process=new JLabel("D",SwingConstants.CENTER);
process=new JLabel("E",SwingConstants.CENTER);
for(int i=0;i<5;i++){
}
JPanel pane2=new JPanel();
pane2.setLayout(new GridLayout(1,2));
priorB=new JButton("Priority");
clearB=new JButton("Clear");
c.setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=0;
gbc.gridx=0;
gbc.gridy=1;
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("");
}
};
}
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:1;
for(;bt>0;bt--){
str+=time+""+processL.getText()+" "+que(time,processL.getText())+"\n";
time++;
}
int ar[]=new int;
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&&bt>0&&!|.equals("4"))
return "E";
return "";
}
public String queB(int time,String l){
if(time>=at&&bt>0&&!|.equals("B"))
return "B";
return "";
}
public String queC(int time,String l){
if(time>=at&&bt>0&&!|.equals("C"))
return "C";
return "";
}
public String queD(int time,String l){
if(time>=at&&bt>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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.