• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class Confusion  RSS feed

 
Kiera Hakikawa
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm taking a Beginning Java class and am having a small problem with a code I'm writing.

The code reads from a file and outputs two arrays based on data from the file.
One array is just the data from the array.
The other is the same data but with the output altered in some way (i.e. String becomes all UpperCase, int = int + 10)

This code is suppose to help with learning extends for a class.
So some data is in the class Trees and some is in the class TreesWithMoreData.
When outputting the altered array I don't know how to alter the data from the second class.

Thank You


 
Junilu Lacar
Sheriff
Posts: 11164
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kiera, while we sympathize with you on your difficulties, it's going to be hard to get anyone to help you if you dump a couple hundred lines of code in a message and say "I'm having trouble, can you help?" without being more specific. Nobody has time to sift through that pile to find the needle that's causing your pain. Sorry, but please whittle it down to fewer lines of code and tell us exactly what you've tried, what you're expecting to happen, and what's actually happening instead that you don't want to happen.
 
Kiera Hakikawa
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a hw assignment that asks to print two array, the first is of a set of data and the second is the same set of data that is slightly altered,
(i.e. Strings are UpperCase, 10 is added to int, etc. ).
Part of the array is in a subclass and I am unsure how to alter the data there because they are in two classes.

I have tried,


But it doesn't compile and gives errors saying sciName and color can't be found in class Trees(name of Superclass) which I understand because the subclass is called TreesWithMoreData.

My question is, how do I call the the subclass and not the superclass to alter the array.

Below is a partial of my code, it's the bits that alter the data and print the second array.

 
Knute Snortum
Sheriff
Posts: 4078
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I completely understand the assignment, but if you want to access all the methods, your array should be type TreesWithMoreData, not just Trees.
 
Kiera Hakikawa
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I'm not sure I completely understand the assignment, but if you want to access all the methods, your array should be type TreesWithMoreData, not just Trees.


I changed,


to,


and it works. So, thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!