#Need some help in a java code

1 messages ยท Page 1 of 1 (latest)

wary masonBOT
#

<@&987246399047479336> please have a look, thanks.

vague sage
#

in the display method i want it to display the input that the user has provided

spiral escarp
#

Paste each class separately so they're easily accessible to helpers. Be clear about what isn't working.

graceful lantern
#

to be honest this looks like homework, and you have nothing in

 public void displayDetails() {
             
        }
wary masonBOT
graceful lantern
#

so how would you approach that?

vague sage
#
public void displayDetails() {
    for (Animal animal : animals) {
        animal.DisplayDetails();
    }
vague sage
graceful lantern
#

It's not really the responsibility of an animal to display it's own details, at most a nice toString method()

#

and you can "display" it using a System.out.println

vague sage
#

i kinda fixed that issue but now as i did it this way

wary masonBOT
vague sage
#

i get an error at line 356 it says : No enclosing instance of type Animal is accessible. Must qualify the allocation with an enclosing instance of type Animal (e.g. x.new A() where x is an instance of Animal).Java(16777237)

#

i didn know how to fix it

dense forge
#

still need to see the entire gist, but be careful on thing that are not suppose to change

#

your putting data in the constructor of animal, and then your making setters aswell

#

Some variables might not have the desire to be changed

#

and can u post the actual code section it is on, as u merged all the code in 1 file, the numbers are most likely not correct

vague sage
#

u mean this ?

#

also to make sure i get the error here

dense forge
#

normally all those classes your posting are suppose to be in each unique file

#

so that line number, is that correct or not ?

vague sage
#

it in :
return new Mammal(name, sex, age, diet, living, furColor);

vague sage
dense forge
#

technicly u can dump all u want in 1 file. Shouldnt really do it though

vague sage
#

its okey m not facing an issue with it anyway

dense forge
#

have u tried creating another animal ?

#

just incase its a problem with the static

#

ah right. U got a typo :p

#

is your Mammal an inner class of Animal ?

vague sage
#

extended from animal

dense forge
#

count your brackets at line 76 then

#

your closing the displayDetails ( and yes your naming is wrong cased ) and then not closing the class, meaning that Mammal is an inner class at that point

vague sage
#

wait

#

whats the diff between a sub class and an inner class

dense forge
#

a child class is an extened one

#

( trying to find a good info page on inner class example )

#

your code problem however is that your class animal is not closed at the point where u think it is. If u look down a bit on Mammal, that one your closing correct

vague sage
#

when i closed animal it said that i should make mammal in another file

dense forge
#

yes your ide is correct :p

#

but u cannot extend inner class with as base the outer class

vague sage
#

and when i make the class zoo in its own file should i make it non static

dense forge
#

yep

vague sage
#

now that i moved each type of animals to seperate files what should i change in the add animal function

dense forge
#

tried running it yet ?

vague sage
#

no i still get errors

#

in add animal method

dense forge
#

can u share the newer version ?

vague sage
#

okey wait

#

somethen about the bracets

wary masonBOT
dense forge
#

right , if that is your current code, addAnimal is in which class ?

vague sage
#

zoo class

dense forge
#

ok. Just to verify, can u yourself hit the Gist button from the post and see where it is ?

vague sage
#

okey wait

dense forge
#

it is quite hard to see code one way , and the poster saying its in another way ๐Ÿ˜‰

vague sage
dense forge
#

ok, that's still the same. If your addAnimal is inside the zoo class, drop the static for starters

#

( on the gist that your posting the method is no where inside a class )

vague sage
#

wait i think i fixed it

dense forge
#

just post the zoo class, that should fix it

vague sage
#

the bracets problem it runs now

#

thanks i really appreciate ur help!

vague sage
#

lol i got an error in the running

#

when i run it and i give information of anytype but mammal type i get this

#

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The declared package "animalss" does not match the expected package "animals"
Syntax error on token "}", delete this token
Syntax error on token "}", delete this token
Syntax error on token "}", delete this token
Syntax error on token "}", delete this token
Syntax error on token "}", delete this token
Syntax error on token "}", delete this token
Syntax error on token "}", delete this token

    at animals.Amphibian.<init>(Amphibian.java:1)
    at animals.Animal.addAnimal(Animal.java:129)
#

after gving the infos

graceful lantern
#

double s

#

and it seems you have one too many bracket

dense forge
#

what IDE are u using @vague sage ?

vague sage
dense forge
#

as long as your code has 1 wrongly placed bracket it will make no sense to the compiler

#

code might be correct but due to the wrong brackets it might get confused

vague sage
#

m using vscode btw

dense forge
#

so fix all the typo's and brackets in there. If your using intellij, bottom right should be a tab called Problems and they should be listed there

#

do yourself 1 favor. Drop VSC

vague sage
dense forge
#

VSC aint made for java coding, 1 second it might work and the next your project is doomed

vague sage
graceful lantern
#

You can code Java just fine in VScode with the right setup, but as a beginner Intellij CE is a bit friendlier

dense forge