• Post Reply Bookmark Topic Watch Topic
  • New Topic

Lost, Don't know where I'm going wrong  RSS feed

 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought I had this correct but it's not compiling.  Any help guiding me would be appreciated.

1) Design a class named Circle that extends the class GeometricObjects. The Circle class contains:

A double data fields called radius , with default values of 1.0, to denote the radius of the circle
A no-arg constructor that creates a default circle.
A constructor that creates a circle with the specified radius.
A getter method to get the instance variable.
A method named getPerimeter() that returns the perimeter of the circle. Perimeter of the circle can be calculated as 2*radius*3.14.
A method named getArea() that returns the area of the circle. Area of the circle can be calculated as 3.14*radius*radius.
A method named toString() that returns a String description of circle as follows:
return super.toString() + “ Circle : radius =  “ + radius + “ area is :   “ + getArea() + “ perimeter is :  “ + getPerimeter();

Create two classes Circle and GeometricObjects and implement the classes.
Write a test program called TestCircleYourName, that prompts the user to enter the radius of a circle, a color and  a boolean value to indicate whether the circle is filled. The program should create a Circle object with the given radius and set the color and filled properties using the inputs. The program should display the area, perimeter, color , and filled values (true or false to indicate whether the object is filled or not). The toString() method should print the values of radius, area and perimeter of the circle.

Please use the classes from the file Week4_4_SampleCode for Assignment_Problem1, as a template for this code. Please use the GeometricObjects code( as given in the sample code)  , as your super class. You will be creating a new sub class called Circle and new tester class called TestCircleYourName. You need not include the subclass called Rectangle in your assignment.

In your TestCircleYourName, under the main method you will test:
Use all the constructors to create objects.
For each object , you will output its value of color, filled and use the toString() method to print the radius, area and perimeter.
For each object, you will reset the color, filled and radius using the setters and then print the  new values of color and . Use the toString() method to print the new radius, area and perimeter


 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Martos wrote:...but it's not compiling.  Any help guiding me would be appreciated. 

Please provide the relevant details when asking for help like that. It would be considerate of you to tell those who would offer help what compiler errors you're getting. Post the exact messages generated by the compiler.
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:
Daniel Martos wrote:...but it's not compiling.  Any help guiding me would be appreciated. 

Please provide the relevant details when asking for help like that. It would be considerate of you to tell those who would offer help what compiler errors you're getting. Post the exact messages generated by the compiler.


Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: GeometricObjects.<init>
at Circle.<init>(Circle.java:4)
at TestCircleDanMartos.main(TestCircleDanMartos.java:5)
/Users/wbrica/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 3 seconds)
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First, please read this ...

https://coderanch.com/wiki/660183/Fix-Compiler-Errors-Running-Application

It is highly recommended that you fix all compiler errors before running the application. Anyway...

Daniel Martos wrote:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: GeometricObjects.<init>
at Circle.<init>(Circle.java:4)
at TestCircleDanMartos.main(TestCircleDanMartos.java:5)


You would probably get a better error message from the compiler in this case... but basically, the error is... The Circle class is a subclass of the GeometricObjects class, but its constructor (Circle class) is trying to call a constructor (GeometricObject class) that does not exist.

Henry
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
First, please read this ...

https://coderanch.com/wiki/660183/Fix-Compiler-Errors-Running-Application

It is highly recommended that you fix all compiler errors before running the application. Anyway...

Daniel Martos wrote:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: GeometricObjects.<init>
at Circle.<init>(Circle.java:4)
at TestCircleDanMartos.main(TestCircleDanMartos.java:5)


You would probably get a better error message from the compiler in this case... but basically, the error is... The Circle class is a subclass of the GeometricObjects class, but its constructor (Circle class) is trying to call a constructor (GeometricObject class) that does not exist.

Henry


Can you elaborate on that a little bit more, I'm new to this
 
Stefan Evans
Bartender
Posts: 1837
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First things first. 
There are errors in the Geometric Objects class you have provided.
The first and most obvious one is that you are missing an 'r' from the class name

It is also missing some attributes.
This class according to the instructions should have been obtained from the sample code.
Make sure you have typed it in correctly - or even better see if you can download and copy/paste it. 
If this is exactly as provided by the instructor, go complain to the instructor for giving you bad sample code which doesn't compile.


Once you can compile GeometricObjects then start on the Circle class

When creating a java object you always have to use a Constructor somewhere.  i.e. new Circle(2)
When dealing with inheritance, the first thing a subclass tries to do is to call the constructor of its parent class.

So given the code


What this is actually going to try and do is implicitly add a call to its parent constructor:


Calling super() in this case would be the same as calling new GeometricObject() - and that constructor does not exist (at least not in the version of the code you provided us).
Instead the geometric object has a constructor:


So you either need to
- add a 'default constructor' to the GeometricObjects class
or
- change your circle class to call the constructor in GeometricObjects:  super(color, filled)

Does that make things clearer for you?

 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:First things first. 
There are errors in the Geometric Objects class you have provided.
The first and most obvious one is that you are missing an 'r' from the class name

It is also missing some attributes.
This class according to the instructions should have been obtained from the sample code.
Make sure you have typed it in correctly - or even better see if you can download and copy/paste it. 
If this is exactly as provided by the instructor, go complain to the instructor for giving you bad sample code which doesn't compile.


Once you can compile GeometricObjects then start on the Circle class

When creating a java object you always have to use a Constructor somewhere.  i.e. new Circle(2)
When dealing with inheritance, the first thing a subclass tries to do is to call the constructor of its parent class.

So given the code


What this is actually going to try and do is implicitly add a call to its parent constructor:


Calling super() in this case would be the same as calling new GeometricObject() - and that constructor does not exist (at least not in the version of the code you provided us).
Instead the geometric object has a constructor:


So you either need to
- add a 'default constructor' to the GeometricObjects class
or
- change your circle class to call the constructor in GeometricObjects:  super(color, filled)

Does that make things clearer for you?



Yes Stefan, thank-you.  My professor is usually very helpful with helping us, but she has been away with emergency.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!