...

View Full Version : Java ";" Expected and illegal start of expression



dtwins
02-03-2012, 06:46 PM
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

Fou-Lu
02-03-2012, 06:59 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum