Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Inheritance with javabean

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Marshal
Posts: 8428
606
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Legend has it that if you rub the right tiny ad, a genie comes out.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic