This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Trying to create a program that uses a Binary Search Tree to keep track of students

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a program that uses a Search Binary Tree to keep track of students that get added and deleted from a list. The program reads a text file that contains certain a command (add, delete, calculate average,etc) followed by the student name, age, and gender. For example, the first line of the text file would be: E Jake 14 M. E would stand for enroll(add).

I'm having issues both conceptually and coding wise.

I have a queue class, a queueLL class that implements the queue class, I have a camper class that returns name, age, and gender, and compares each student name, and lastly I have my search binary tree class.

The issue is in the main class:

I don't think my implementation is correct and I am hitting a wall in terms of trying to finish the code. I get errors of trying pass the file argument in Camper

The values define were 3 strings in my Camper Class file (name, age, gender). Any Help would be appreciated!

Edit Code for Camper:

Posts: 70351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure. But I can see the keyword static appearing frequently. Why? I always work on the assumption that any sue of static must have a good explanation, otherwise it is a mistake. You should move nearly all that code out of the main method into instance methods. Your use of static would imply that you only have one camp anywhere, but instance methods would permit multiple camps.
Why have you used on demand import for and imported one class from java.util by name. Prefer single imports to on demand. I can see you opening Scanners but I can't see you closing them.
Why have you made your compareTo method so complicated, when you are only comparing the String field? You can simplify that no end. What happens if you get two people with the same name and different ages?

You cannot pass a file to the camper constructor because you specified three arguments. You have to read name age gender from your file and pass those individually.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic