Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-03-2012, 06:46 PM   PM User | #1
dtwins
New to the CF scene

 
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dtwins is an unknown quantity at this point
Java ";" Expected and illegal start of expression

ey guys, need help with java not compiling, here is the code and errors.

[CODE]
/** PROGRAM ASSIGNMENT 1 DaltonBrandonP2.java
*
* Author: Dalton Brandon
* Class: Java, Online
* Due Date: February 8, 2012
* See if roof needs changed, calculate price per square foot
*/


import java.util.Scanner;

public class DaltonBrandonP2 {
public static void main(String[] args) {
System.out.println("Dalton Brandon, Program Assignment 2, Java, online");
//New Scanner
Scanner input = new Scanner(System.in);

while (again == 1) {
//Year house was built
System.out.print("What year was the house built?: ");
int year = input.nextint();

//Square foot of house
System.out.print("Enter square feet of house: ");
double square = input.nextdouble();

//Total price
System.out.print("Enter total price: ");
double price = input.nextdouble();

//Does roof need changing?
void ifRoofChangeNeeded(int year){
if ((2012 - year) >= 15)
System.out.print("Roof change is needed");
else
System.out.print("No roof change is needed");
}
//Calculate price per square foot
void calcPricePersqf(double square, price){
int priceSqrf = price / square;
System.out.print("Price per square foot is: " + priceSqrf);
return priceSqrf;
}

System.out.print("Work on another house? 1 for YES, 2 for NO: ");
int again = input.nextint();
}
}
}
[CODE]

ERRORS

C:\Users\Dalton Brandon\Desktop\JAVA\Assignment 2\DaltonBrandonP2.java:32: error: illegal start of expression
void ifRoofChangeNeeded(int year){
^
C:\Users\Dalton Brandon\Desktop\JAVA\Assignment 2\DaltonBrandonP2.java:32: error: ';' expected
void ifRoofChangeNeeded(int year){
^
C:\Users\Dalton Brandon\Desktop\JAVA\Assignment 2\DaltonBrandonP2.java:32: error: ';' expected
void ifRoofChangeNeeded(int year){
^
C:\Users\Dalton Brandon\Desktop\JAVA\Assignment 2\DaltonBrandonP2.java:39: error: illegal start of expression
void calcPricePersqf(double square, price){
^
C:\Users\Dalton Brandon\Desktop\JAVA\Assignment 2\DaltonBrandonP2.java:39: error: ';' expected
void calcPricePersqf(double square, price){
^
C:\Users\Dalton Brandon\Desktop\JAVA\Assignment 2\DaltonBrandonP2.java:39: error: ';' expected
void calcPricePersqf(double square, price){
^
6 errors

Tool completed with exit code 1
---------------------------------------------------------------------------------------------------------

Am using TextPad, required for class
dtwins is offline   Reply With Quote
Old 02-03-2012, 06:59 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You cannot nest methods in methods like this. Both of these methods have been placed inside of your main method, so remove these and add calls to them instead.
The methods will also need to be static, or you will have to construct an instance of this class.
Everything else looks fine.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
code, error, expected, illegal, java

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:09 AM.


Advertisement
Log in to turn off these ads.