Results 1 to 3 of 3
  1. #1
    nutdeep is offline Member
    Join Date
    Sep 2015
    Posts
    4
    Rep Power
    0

    Default Getting this error "Syntax error on token ";", { expected after this token"

    package week4;

    public class Shape {

    public static void main(String[] args){}

    protected double surfaceArea;
    protected double volume;
    protected double radius;
    protected double pi = Math.PI;
    boolean end = false;

    public double surfaceArea(double surfaceArea) {
    this.surfaceArea = surfaceArea;
    return this.surfaceArea;
    }
    public double volume(double volume) {
    this.volume = volume;
    return this.volume;
    }
    public double radius(double radius) {
    this.radius = radius;
    return this.radius;
    }

    // Getting the name of the class
    public String getThisClass() {
    String thisClassString = this.getClass().toString();
    String newString = "";
    char character;
    boolean start = false;

    for (int i = 0; i<thisClassString.length(); i++) {
    character = thisClassString.charAt(i);

    if(character == ' ') {
    start = true;
    }
    else if(start == true) {
    newString = newString + character;
    }
    else {
    // aka doing nothing here, loop over and over
    }
    }
    return newString;
    }

    public String toString() {
    // Get name of shape we want to work with
    String thisClassIs = getThisClass();

    // For a sphere
    if ((thisClassIs).equals("Sphere")) {
    end = true;
    return "SPHERE\nVolume: " + this.volume + "\nSurface Area: " + this.surfaceArea + "\nRadius: " + this.radius;
    }
    // For a cube
    else if((thisClassIs).equals("Cube") && end == false) {
    return "\n\nCUBE\nVolume: " + this.volume + "\nSurface Area: " + this.surfaceArea + "\nRadius: " + this.radius;
    }
    else {
    return "Volume: " + this.volume + "/nSurface Area: " + this.surfaceArea + "\nRadius: " + this.radius;
    }
    }

    public class Sphere extends Shape {

    private double r;

    public Sphere(double a, double c, double r) {
    this.radius = r;
    volume();
    surfaceArea();
    }
    public double volume () {
    volume = (4/3) * super.pi * Math.pow(r, 3);
    return volume;
    }

    public double surfaceArea() {
    surfaceArea = 4 * super.pi * Math.pow(r, 2);
    return surfaceArea;
    }
    }

    public class Cube extends Shape {

    private double r;

    public Cube(double a, double c, double r) {
    this.radius = r;
    volume();
    surfaceArea();
    }
    public double volume() {
    volume = (4/3) * super.pi * Math.pow(r, 3);
    return volume;
    }

    public double surfaceArea() {
    surfaceArea = 4 * super.pi * Math.pow(r, 2);
    return surfaceArea;
    }
    }
    public class ShapesDriver {

    // Puts in surface area, volume, and radius
    Cube cuboid = new Cube(5.7, 6.9, 8.5); //Here is where the error "Syntax error on token ";", { expected after this token" occurs
    return cuboid;

    Sphere globe = new Sphere(5.7, 6.9, 5.0);
    return globe;
    }
    }
    }

  2. #2
    nutdeep is offline Member
    Join Date
    Sep 2015
    Posts
    4
    Rep Power
    0

    Default Re: Getting this error "Syntax error on token ";", { expected after this token"

    The error is mentioned in my code.

  3. #3
    nutdeep is offline Member
    Join Date
    Sep 2015
    Posts
    4
    Rep Power
    0

    Default Re: Getting this error "Syntax error on token ";", { expected after this token"

    Nvm. Got it.

Similar Threads

  1. Replies: 3
    Last Post: 03-09-2014, 07:57 AM
  2. Syntax error on token "(", @ expected and more errors
    By ebrown086 in forum New To Java
    Replies: 4
    Last Post: 08-17-2013, 05:31 PM
  3. Syntax error on token "}", super expected
    By amentjacob1 in forum New To Java
    Replies: 9
    Last Post: 07-06-2012, 04:15 AM
  4. Syntax error on token "(", ; expected
    By baltimore in forum AWT / Swing
    Replies: 3
    Last Post: 10-28-2009, 12:19 AM
  5. Syntax error on token "(", ; expected
    By romilc in forum New To Java
    Replies: 7
    Last Post: 10-24-2009, 01:23 AM

Posting Permissions

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