• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

calculation float problem, and alot of errors and been trying to fix this problems for days.

 
Greenhorn
Posts: 16
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The requirements are:
•Write an application that will allow a user to input (use dialog boxes) the parent's heights and then outputs the predicted height as a range
•Implement a person class that has:
attributes for gender and height,
a constructor with two parameters (gender and height),
a constructor with one parameter (gender),
a constructor with one parameter (height),




 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lines 7 and 8 of class Person, and lines 42 and 43 of class ChildHeightPredictor are, sorry for the harsh word, terrible. Never, ever use two variables with the same name that differ only in capitalization. Remove the uppercase version, you don't need them. Then fix the compilation errors you will get afterwards.

Next, the setHeight and calcAverage methods take a Person parameter - I'm not sure what calcAverage should be taking, but setHeight should work analogous to setGender.

Now we're getting to the error in line 50 of ChildHeightPredictor. The problem is you're using variables before assigning values to them. At that point in the code, you can't calculate anything, because only the gender of the child has been entered. So it seems the entire logic needs to be reworked.
 
Ricardo Arteaga
Greenhorn
Posts: 16
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


okay i fixed this, so far the calAverage should be a float to basically calculate the child height in decimal but iono how do that correctly.
 
Ricardo Arteaga
Greenhorn
Posts: 16
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for childHeightPredictor how can i work on the logic because i do not know where to start?
i did two integers for father and mother and parse them. But i dono if i need to turn double to float,
is there a guide or video that explain the logic correctly.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code is much better. You can remove lines 3 and 4, they don't do anything. Line 30 is correct, but in line 28, height is an int, not a Person.

What is the formula for calculating the expected child height? Does it depend on the gender? If so, how?
 
Ricardo Arteaga
Greenhorn
Posts: 16
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but basically when user enter female and adds value it should tell you the height value in float
or if user enter male tell height value in float based on gender.

The objective of my program is : For our next programming assignment we will write
an application that uses a relatively simply
predictive approach that is actually quite good:

1.Find the average of the parents’ height by
adding together the mother’s and father’s height
(either in inches or centimeters) and dividing by 2.

2.To calculate the height of a boy, add 2.5 inches
(6.5 centimeters) to the average of the parents’
height. To calculate the height of a girl,
subtract 2.5 inches (6.5 centimeters) to the
average of the parents’ height.

3.The resulting number is the “mid-parental height”
for girls or boys. The child’s adult height can be
expected to fall within a range of 4 inches
(10 centimeters) less or more than the
mid-parental height.

The requirements are:

•Write an application that will allow a user to
input (use dialog boxes) the parent's heights and
then outputs the predicted height as a range

•Implement a person class that has:

•attributes for gender and height,

•a constructor with two parameters (gender and height),

•a constructor with one parameter (gender),

•a constructor with one parameter (height),

•a default constructor,

•methods to get and set the attributes, and

•a method that accepts two parameters (Person objects)
and returns the estimated height as a float


I remember if it is a female child you subtract the age. if it is a boy child it is added.
------------------------------------------------------------------------------------------------------------------------------

i found this link that explains it: https://coderanch.com/t/569079/java/java/loops

 
Ricardo Arteaga
Greenhorn
Posts: 16
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
fix the line


and delete java.awt
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic