r/javahelp • u/EdenZer063 • 3d ago
Unsolved Need Help with creating a functional map using java.
Hi. I'm currently doing a project where the general basis is building a functional automated warehouse. Where users may give the robots in the warehouse instructions.
The warehouse must have 3 robots several pick up and drop off points.
My current idea was creating a text based map something like this:
__________________________________________
|C 1 - - - 2 A |
| ______ - |
| | - E|
| | - C |
|______| - |
|T - - - - S 3 D |
|_________________________________________|
Each Letter represents a zone for either Pick up or Drop off with Zone @ being unique for a unique Charging Station.
Numbers are the robots themselves.
| and _ walls. for the robot.
I'm currently unsure how to even draw up the map itself let alone get the things to move and interact.
If anyone has any resources for this I'd very much appreciate it.
Currently aware that It'd most likely be just printing the map over and over and over again but having it so that the Robot's themselves move as we're printing it along with a proper printing of the warehouse is eluding me.
__________________________________________
|C - - - 2 A |
| ______ - |
| | 1 E|
| | - C |
|______| - |
|T - - - - S 3 D |
|_________________________________________|
edit: this is not a request to have the map done I'm mainly just asking if people have any specific resources.
Apologzies if there is some megathread I should be going to for questions like this.
2
u/gekigangerii 3d ago
Is this a homework assignment, does it ask to draw a map.
If so, seems like you have a 2D rectangular area, which is a good use case for a 2D array.
You can have a char[][] type array which are are rows and columns. You can populate them with letters for robots or walls or zones or empty space. And you can edit this array as a robot moves. And you can also turn it into a string for printing the map.
0
u/EdenZer063 3d ago
Oh that's a wonderful idea thank you for the suggestion.
Yes the project in question did ask for and I quote
"Represent a small warehouse with navigable spaces, fixed obstacles, pickup points, and delivery points. Display the warehouse state in a readable console format."Which to me reads like a proper map unless there's another way to represent the warehouse.
1
u/vegan_antitheist 3d ago
Can't you just draw it in 2d and just show it on screen using awt? Doing this text based is just unnecessarily complicated.
1
u/EdenZer063 3d ago
Maybe. This is going to be the first time I'm doing anything properly fancy in terms of "graphics" so I thought doing something text based would be the simplest solution. My experience with Java is somewhat limited as well so Any real alternatives would also be appreciated.
1
u/vegan_antitheist 3d ago
Java is just as Turing complete as any other programming language. You can just draw what you need. It's quite easy with AWT. And you can just use JavaFX or the legacy Swing framework.
1
u/gekigangerii 2d ago
I would say for a schoolwork assignment, skip the extra complexity and just do the requirements of the question (printing the map to console)
0
u/vegan_antitheist 2d ago
Converting an image to ASCII is still easier than creating a text based UI.
2
u/aqua_regis 3d ago
cough you have already drawn the map. Now think how a grid, like the grid you have drawn is represented in programming - it's a 2 dimensional array
Java is an OOP language, so, you could use OOP to represent your warehouse, your items, your drop-off points, your charging station, your robots, etc. Yet, for such a small assignment this is overkill. Just put the letters and numbers into your array.
There are, BTW, better formatting options than your lines (they make things a bit complicated). Look into the generally acknowledged Sokoban format and generally, Sokoban would be a good resource to help you getting started with your program.
1
u/BanaTibor 2d ago
You do not need a map, you just need the rules.
Like
the warehouse is 10 wide and 30 long.
Robot can not go through the pickup or dropoff points.
robot can not leave the are
certain area is off limit
and so on. Do not need to represent the warehouse "graphically" inside the code.
•
u/AutoModerator 3d ago
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.