Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •