Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help with the space-time continium

 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or dis-continium, as the case may be.

Please suggest a data structure that will hold unique combinations of space and time values, specifically, apartments and dates they are occupied.
I will need to check whether a certain combination of these two against this data structure to determine whether an apartment is available or not for a particular date.

Thank you.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like you need to create an object of some sort... and store a bunch of them in whatever suits your fancy to solve your problem.

Good luck with your homework. ShowSomeEffort and you might get some better responses.
 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hoped someone could mention the name of a structure suitable for storing unique combinations of 2 variables that I can check against.

I came across "set" and think this might do the trick:



I would concatenate the 2 variables and check them against a set.

Thanks
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Janeice was right -- create a class which contains (something like) an apartment name and a date. Concatenating strings is a really really bad way of designing an object. You'll need to write an equals() method which can compare two of these Occupancy objects, or whatever you decide to name your class.
 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:No. Janeice was right -- create a class which contains (something like) an apartment name and a date. Concatenating strings is a really really bad way of designing an object. You'll need to write an equals() method which can compare two of these Occupancy objects, or whatever you decide to name your class.

I suppose once I figure out how to create an object I can store it in a set as above.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. Don't forget that when you override equals() you'll also need to override hashCode()
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hashCode(), not hashcode().
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ehm I'm sure that some radiation from Japan changed some bit values in my computer resulting the change from C to c
Anyway I've corrected it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you create some sort of calendar to be attached to the Apartment object? Then an Occupancy object which incorporates a timespan?

That question looks like something which is easier to handle in SQL.
 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Can you create some sort of calendar to be attached to the Apartment object? Then an Occupancy object which incorporates a timespan?

That question looks like something which is easier to handle in SQL.


I know the right answer is yes.
Once I learn to create objects, extend classes, override methods, etc...
I do want to learn to do things the right way.
I think I will start going through http://download.oracle.com/javase/tutorial/java/index.html to get basics.

I really appreciate all responses. Thank you very much.

In the meantime, my understanding is very limited.
As in, I did not know the difference between Pattern.matches and matcher till yesterday.
This project is for a one-off script and it does not even use real Java, but Interpreted Java, which I think is BeanShell.
It might have to be something quick and dirty with this one.

 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ilya Mechnikov wrote:I hoped someone could mention the name of a structure suitable for storing unique combinations of 2 variables that I can check against.

I came across "set" and think this might do the trick:



I would concatenate the 2 variables and check them against a set.

Thanks


WHOA!!!

Now now.... using Strings to do the job of Objects is a VERY BAD plan..... people start doing this and get wound up on the bad side of the tracks.

At the very least use a Map<String, Date> to do what you need. The String should be the KEY and the Date should be the VALUE. See if you can figure out why.

I still would do this (in like 7 lines of code so it's quick and dirty enough)



Then you can keep a List<Apartment> or Set<Apartment> or Map or whatever with the objects in it.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. starting with learning regex / pattern matching before understanding how to instantiate an object is also a very bad plan.
 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janeice DelVecchio wrote:P.S. starting with learning regex / pattern matching before understanding how to instantiate an object is also a very bad plan.

Thank you very much.
I used to write awk/sed and perl scripts in my past life as Unix sysadmin so regex is nothing new, maybe a bit rusty.
I suppose where I come from "everything is a string".
OOP is a completely new bowl of wax, I am still thinking in terms of stringing unix utilities together.
So, when you suggested to create an object of some sort it made no sense whatsoever until later when someone else touched on it and I understood that you gave some succinct advice,
which sadly I can't execute yet.


 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's actually pretty easy to create an object and use it. What do you use for reference materials?

There's no reason not to learn things the right way. It's not hard or complicated and it might only take you a couple hours total to get the job done well.

There's also no excuse if you've come from coding perl. Its a bit watered down, but uses many similar OOP concepts.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ilya Mechnikov wrote:. . . Once I learn to create objects, extend classes, override methods, etc.... . . .
You don't need to extend anything or override. As Janeice has told you, you can probably do this without inheritance.

You need pencil and paper and a big eraser. Write down how you would do this. Do it in words of one syllable; remember you are instructing a machine with no intelligence. Drawing diagrams would help too.
 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janeice DelVecchio wrote:It's actually pretty easy to create an object and use it. What do you use for reference materials?

There's no reason not to learn things the right way. It's not hard or complicated and it might only take you a couple hours total to get the job done well.

There's also no excuse if you've come from coding perl. Its a bit watered down, but uses many similar OOP concepts.


I do want to learn.
As far as books, I have 'Java The Good Parts' and like its level of explication.
Other than that, I am getting feel for http://download.oracle.com/javase/6/docs/ and expect that will be my main reference going forward.
I often need more examples to understand the docs so I've been searching the web for those.
What else could I do?
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects have 2 simple jobs in life....

1. They know things (called "having state")
2. They do things (called "having behavior")

You should make a list of the things your Apartment object should know (date available, street, address number, apartment number), and the things it should be able to do (change available date, other stuff?). Once you have that list, we can create the class, one step at a time, then create functions that use that class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic