47 Replies
on the lines where it says "Convert.To........" there's errors saying i can't do that, but i don't know how to work around it because i need those numbers in the files to be numbers, not strings
i am using an abstract class as a base and reated derived classes and then made instances of those derived classes
What are you trying to convert to that integer?
Three values all at once?
Or are you hoping that by passing
'3', '4', '5'
it will somehow figure out you want to convert "345"
?
Not to mention, you're converting to int
, like the name of the method implies... and trying to save the result in a variable of type BoxCar
None of that makes any modicum of sense, I'm afraidhell, i need a cig
at first i had it as, for example, "boxcar = Convert.ToInt32(nextItem[1]); because i wanted to take the value read from the input file and make it an int instead of a string
Yes, that's how you can use
Convert.ToInt32()
. It turns a string into an integer, correcti did that but i still kept getting an error
Because
boxcar
is of type RailroadCar
Not int
Square peg does not fit round holei get that, but i am unsure how to work around it because i need them to be int and then i need to take those values and run them thru my Volume() method
am i to create just a random variables in my main program ?
Try... using a different variable?
Don't assign an integer to a railroad car?
Make another variable for that integer
Then you can do
boxcar.Something = theNewVariable
And boxcar.SomethingElse = anotherNewIntegerVariable
Alternatively, you can skip that step
okay, i will try that, pleadse allow me a moment
okay so still using boxcar as the exmaple
i already have the instance
do i keep this and use the boxcar.ThingOne example, or completely get rid of that instance ? because I am running into an error still since it is a method group
You keep that
Alternatively, you can use initializer syntax
And initialize all three properties in one go
That said, unless you're not calling a method somewhere but are tryint to access it like a property, you should not be getting any errors related to method groups
i still don’t get what i’m doing wrong 😭😭
GetLength
is a method
A getter at that
You cannot assign values to methods
You can only assign values to properties
The car should have properties for width, height, and length
With that, you can do
and
this is my railroad car file
he wanted it to look specifically like this
Then you need to use
.SetLength()
car.SetLength(69)
You're doing a lot of useless work here, but sure, if that's what you need go aheadi've been tild my prof is insaely out of date and makes us do a lot of unnecessary work 😭
but issn't that still a method group ? and we won't know the specific numbers he's using because he uses his own input fil
file
You were trying to assign to a method
This is calling the method
And instead of
69
use your converted number
I used a hardcoded number for brevityso i'd do
Yep
or no
okay ill try that
plz hold
okay that;s working, but that's not working for width and height
Do you have setter methods for width and height?
i do yes
my boxcar file
Ah, see, those required
double
Not int
im gonna throw up 😭
it's like he enjpys being difficult
It's not difficult
even then tho
Convert to double instead of it ¯\_(ツ)_/¯
I can't call SetWidth or height
ik that but i cant call width ot height
i keep getting an error
That error being...?
oh wait hang on
i think i figured it out
i did NOT figure it out LMAO
it's saying that there's no defintion for SetWidth in the base class
ik boxcar is derived from the base class, but boxcar has width and height
Probably because the variable is of
RailroadCar
type, not BoxCar
:00000
ok plz hold
okay so i fixed that issue, now when i try writing the actual volumes to the output file, it's blank
How are you writing the file?
i can't put parameters either bc ill get an error
Again
What error
itll say there's no parameters for the method Volume()
Does the method take any parameters?
no, that;s why i left it blank, but i don't know how else to return the volume
What is the error exactly?
when i try adding parameters, it says "no overload for method 'Volume' takes 3 arguments"
otherwise there's no errors
You said the method doesn't take any parameters
Why are you trying to give it 3 parameters then?
yes i know that;s why i left it blank
im saying im teying to find out how to use those number to calc the volume, but don't know how since there's no parameters
the method only returns the volume
You do it inside the volume method
And you use the properties of the class to do that
Or, well, fields in your case
could u explain a bit more please, im not following
Angius
REPL Result: Success
Console Output
Compile: 781.215ms | Execution: 65.533ms | React with ❌ to remove this embed.
what i have in the volume method is already there tho in all the files
this is all so confusing
what's up there is already in my files , hto not exactly to fit what i have to do for my assignment
Yeah, this looks like it would calculate the volume
okay good
if that's right then, idk why my output file is still blank
😭