//this method should //1) prompt the user for the address and price of the house //2) create a new House with the address and price listed //3) place the house into the array of houses public void addHouse() throws Exception { System.out.println("What is the address and price of the house you would like to add, seperate them with a ':'"); String bits[] = kb.readLine().split(","); if(bits.length != 2) { System.out.println("invalid data entered"); } else { int newAdd = Integer.parseInt(bits[1].trim()); house[ctr] = new House(bits[0].trim(),newAdd); saveToFile(house[ctr]); ctr++; System.out.println("House added as:" + bits[0] + "," + bits[1]); } } public void saveToFile(House house) { System.out.println("Enter the file name to save to"); try { String fyle = kb.readLine(); FileWriter fw = new FileWriter(fyle,true); fw.write("House : "+house.address+":"+house.askPrice+"\r\n"); fw.close(); } catch(Exception e){errorHandler();} } //this method should //1) ask the user which houses to display and in what order //2) sort the houses according to the criteria entered //3) display the houses according to the criteria entered public void displayHousesMenu() throws Exception { } //this method does: //1) prompts the user on the order in which to display the agents //2) sorts the Agents by the choice given by choice //3) display the list of Agents public void displayAgentMenu() throws Exception { for (int i=0; i<ctr; i++) { System.out.println(house[i].toString()); } menu(); } //this method should //1) prompt the user for the name of the file that contains the list of houses and agents //2) read in the list of houses and agents //3) if line starts with house create a House object and add to list of houses //4) if line starts with agent create an Agent object and add to list of agents public void readInFile() throws Exception {

fr.close(); } } catch(Exception e){errorHandler();} } //this method should: //1) prompt the user for the name of the file containing the list of houses sold //2) for each house sold, mark the corresponding house object sold // and add it to the list of sold houses in the selling Agent and purchased houses in the buying Agent public void updateSoldHouses() throws Exception { System.out.print("Enter the filename in which the house sale information is stored: "); // read the filename from the keyboard String filename = kb.readLine().trim(); // initialize a BufferedReader to read from the file BufferedReader file = new BufferedReader(new FileReader(filename)); String lineRead; //read a line from the file lineRead = file.readLine(); //while text can be read from the file, keep reading

} //this method: //displays the list of choices to the user and prompts for input //returns the choice the user made public int menu() throws Exception { System.out.println("1. Add new house for sale"); System.out.println("2. Display houses"); System.out.println("3. Display agents"); System.out.println("4. Update sold houses"); System.out.println("5. Exit"); System.out.println("Please select one of the options:>"); int choice = Integer.parseInt(kb.readLine().trim()); return choice; } //there could be some useful methods such as getAgent and getHouse public Agent getAgent(String name) throws Exception {

} public House getHouse(String address) { } //There will be other methods needed to do sorting etc. //this method just shuts down the program if ever an invalid argument is typed in public void errorHandler() { System.out.println("I/O error - terminating."); goodBye(); } //this thanks the user for using the program then closes it public void goodBye() { System.out.println("\nThanks for using the Phone Book. \nGoodbye."); System.exit(0); } public static void main(String[] args) throws Exception { Emacs e = new Emacs(); e.menu(); } } i just can't get any of my other methods working, sorry if this seems like an ambiguous question.

i just can't get any of my other methods working, sorry if this seems like an ambiguous question.

No reason to be sorry. This forum will still be here when you get your thoughts together and ask a specific question that we can help you with, without compromising the education you (or your parents) are paying for atthe Univeristy of Saskatchewan [ November 13, 2003: Message edited by: Joe Ess ]

(...) and joe, as for compromising my education, which i pay for, how does (...) when i am trying to get assistance on an assignment i don't understand compromise my education any less than me asking a superfluous question in the hopes that i might actually learn something? (... == stuff removed by Paul Wheaton) [ November 17, 2003: Message edited by: Paul Wheaton ]

JavaBeginnersFaq"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt

Nick Allen

Ranch Hand

Posts: 47

posted 14 years ago

Thanks Marylin, for giving some direction as to what questions to ask. All the code I have in there so far works. I need to create a sort of some kind that will sort the houses by price (ascending or descending, whichever is easier). I also need to sort houses by adress, whether by number or alphabetical order is not specified. I have to create a method that will track the profits of each specific agent. ie. total sales, total purchases; and then i need to sort the agents by those criteria. So I guess what would help me most is a sort method that can be easily configured all four of those applications listed above. I hope this seems a little clearer.

Originally posted by Nick Allen: So I guess what would help me most is a sort method that can be easily configured all four of those applications listed above.

I'm a little confused. Are you looking for somebody to write a sort method for you? Or do you have some particular bit of code that isn't working and you can't figure out why? If it's the latter, I'm sure people here would be more than happy to help if you can show us what you've got so far for the sort method, and what output or errors you are receiving versus what is expected. If it's the former, RentACoder might be a more appropriate place to start. [ November 14, 2003: Message edited by: Jason Menard ]

Ha! Houses, sorting... I knew this sounded familiar. One of your fellow students was by here just a week ago, and we answered this question already. He didn't like the answers much, though. See here and here.

Sorry that looks a bit messy. I get a missing return statement error at the end of that method, just after the last squiggly bracket. I'd kinda like to know why and what I need to do about it. All the methods referred to already exist in the rest of my code. [edited by Tom - the code tag is your friend] [ November 14, 2003: Message edited by: Thomas Paul ]

The method is declared to return "int", which means that every path out of this method must end in a "return x" statement, where x is an integer expression. You've got not "return" at all; if you want to return a value, do so; otherwise, change the method declaration to return void. [ November 15, 2003: Message edited by: Ernest Friedman-Hill ]

Please try to get in the habit of encloding code you post here in UBB CODE tags. See the UBB Code instant "CODE" button on the page where you post your message, or the What is UBB Code? link right below the instant UBB Code buttons. To answer your question, your method signature:public int menu() throws Exception states that your menu() method should return an int. Your code however has no return statement, nevermind one that returns an int. Perhaps the return type of your method should be changed?

Nick Allen

Ranch Hand

Posts: 47

posted 14 years ago

Alright that works now. How do I make the agents able to sell and buy houses, is there some kind of proprietary method that can assign one object to another then allow the assigned object to change hands to another agent object?

Superfluous. I have to say it a few times. Superfluous. Superfluous. There's a few different ways to pronounce it. Or try to, anyway. Superfluous. I start off thining of Superman and end up thinking of librarians. Mmmmmmm, librarians .... And then I have to think to remember what it means .... Oh wait. I'm supposed to act important .... Nick, I think you'll find that JavaRanch is packed with people just itching to talk about java in any way that anyone can think of. They're just sort of goofy that way. Fortunately, there's a lot of threads going at any time, so a person could jump in just about anywhere. Most of the folks who ask a question have asked a question or two in the past and have figured out the best way to ask a question. After all, some folks don't ask "the right way" and nobody answers their question. In this case, somebody decdided to not answer your question, but felt for your situation and thought that if he gave you some tips on how to ask questions, he (and others) might be more likely to help you out. But he didn't have a lot of time, so he rushed ... Marilyn, as you have discovered, is a kind and generous soul. She took a lot of time from her very busy day to help you to understand why folks weren't too keen on helping you. by browsing this thread a bit, I think the main points are covered. Asking folks to read all that code is a mighty high price. You probably eliminated about 90% of the people that might help you right there. The lack of formatting probably turned some people off too. To mention that it's a homework assignment turns a lot of people off. They're not going to be sure what to do. Is helping you wrong? And then there is the ambiguity part that you recognized. Ambiguity is okay as long as you can give some clue on what you know and what you don't know. And finally, saying mean things to somebody trying to help you is a bit of a turn off too. So from the perspective of somebody who wants to help you, this looks like lots of work and pain and not a lot of fun. There are other threads that will be lots of fun, and virtually zero work or pain .... For future questions I would like to suggest that you keep your code fragments short and in code tags. Try to talk a little about what you know and what you don't. Ask for understanding, not for code. For this question, I would like to ask that you edit your posts that might say anything less than kind about other folks. I think I might change my title to "blabbing like a narcissicistic fool with a superiority complex". I think it's spelled "Narcissistic". Narcissicistic. Narcissicistic. You would think it would be a tongue twister, but it really isn't too bad. Kinda reminds me of that saying "Power corrupts. Absolute Power is pretty neat."

Originally posted by Paul Wheaton: To mention that it's a homework assignment turns a lot of people off. They're not going to be sure what to do. Is helping you wrong?

Don't take that to mena that you cant post a question about homework here. We're all more than happy to help with homework, most of have gotten help ourselves on homeowrk at one time or another. The problem would be that most of us don't want to give the answer to someone who can't/doesn't show that they put in some effort to it themselves. Paul, here's a good one. Toy Boat Toy Boat Toy Boat Try that three times...

Dave

Nick Allen

Ranch Hand

Posts: 47

posted 14 years ago

i need to know where to begin with sort methods. i know i need to write four of them, but they are all pretty similar, just order objects in an array based on numerical value. i want to find the lowest value, put it first, then the second lowest, put it second..... until the end of the array, i thought i could do it with just a for loop, but those haven't worked for me at all, any suggestions for what to do would be greatly appreciated