aspose file tools*
The moose likes Beginning Java and the fly likes need help with the space-time continium Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help with the space-time continium" Watch "need help with the space-time continium" New topic
Author

need help with the space-time continium

Igor Mechnikov
Ranch Hand

Joined: Feb 13, 2011
Posts: 100

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.


String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1732
    
  12

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.


When you do things right, people won't be sure you've done anything at all.
Igor Mechnikov
Ranch Hand

Joined: Feb 13, 2011
Posts: 100

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
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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

Joined: Feb 13, 2011
Posts: 100

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

Joined: Oct 25, 2008
Posts: 2700

Indeed. Don't forget that when you override equals() you'll also need to override hashCode()


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

hashCode(), not hashcode().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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

Joined: Oct 13, 2005
Posts: 40038
    
  28
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

Joined: Feb 13, 2011
Posts: 100

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

Joined: Sep 14, 2009
Posts: 1732
    
  12

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

Joined: Sep 14, 2009
Posts: 1732
    
  12

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

Joined: Feb 13, 2011
Posts: 100

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

Joined: Sep 14, 2009
Posts: 1732
    
  12

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

Joined: Oct 13, 2005
Posts: 40038
    
  28
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

Joined: Feb 13, 2011
Posts: 100

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

Joined: Sep 14, 2009
Posts: 1732
    
  12

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help with the space-time continium