Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance with javabean  RSS feed

 
Nicola Bali
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone
I'm new of the forum and english is not my native language. Sorry if sometimes will be some grammatical error.
I'm new also in the Java world and I'm doing some exercise to practise it.

The exercise I'm doing is: I want to write a program that when I insert 3 numbers that represent each one a side of a triangle, the program have to recognise if the triangle is: isosceles, equilateral, scalene.
It seems pretty simple.

I structured the logical:

3 packages
- default package: i have the main class



The package Figure where i have the class Trinagolo



The package Geometria where there are three classes, each one represent a kind of triangle

Equilateral Triangle


The isosceles triangle


and the scalene triangle (pretty the same structure of the previous triangles)

Now ... my problem is that the in the main class return null.

For sure something is wrong, probably also the logical that i thought to solve the exercise.

Someone can help me?

Thanks a lot
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicola Bali wrote:
Now ... my problem is that the in the main class return null.

For sure something is wrong, probably also the logical that i thought to solve the exercise.

Someone can help me?


Your main() method creates a Trinagolo instance. Set the three sides (A, B, and C) -- which doesn't do anything else, such as setting the result. And then you get the result. Since the result was never set, it is null.

Henry
 
Nicola Bali
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry

I would like set the result on the three classes that represent the kind of triangle which extends the javabean Trinagolo.

Trinagolo is the javabean with the setter and getter methods. It suppose to takes each side of the triangle from the main class through and the result from the classes: Equilateral Triangle and Isosceles triangle.
In these classes I'm trying to set the result


and the pass it at the main class through


 
Liutauras Vilda
Marshal
Posts: 4634
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain at which line you're calling method to calculate/set result?

[edit]
Anyway, it won't work that way as you think it will work. At maximum what you can achieve now, is to set somehow result of Triangolo class and get that, but it is not what you want to do.
Hint: you're creating an object of Triangolo class, and the other classes methods you're not able to use.

Start by reading at Inheritance section and finish after Polymorphism, so you could refresh your minds about these two concepts.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!