• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

writer's block on assignment, any help?

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These are my object classes:
House:
class House
{
String address;
int sellPrice;
int askPrice;
boolean sold;

public House(String newAddress, int newAsk)
{
address = newAddress;
askPrice = newAsk;

}
public String getAddress()
{
return address;
}
public int getPrice()
{
return askPrice;
}

}
Agent:
class Agent
{
String name;
int totSales;
int totPurch;

public Agent(String newName)
{
name = newName;
}

}
and the main program (it models a real estate co. that tracks sales of agents and allows houses to be bought below asking price):
import java.io.*;
import java.util.*;
public class Emacs
{
BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
House house[] = new House[1000];
Agent agent[] = new Agent[1000]; //you may add more variables
int ctr = 0;

public Emacs() throws Exception
{
readInFile();
menu();//add your code for initializing all instance variables
}

//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
{

System.out.println("Enter file name you wish to use");
try
{
String fyle = kb.readLine();
File usersFile = new File(fyle);
if(usersFile.exists())
{
BufferedReader fr = new BufferedReader(new FileReader(fyle));
String line = "";
String bits[];
while ((line = fr.readLine()) != null)
{
bits = line.split(":");

if(bits[0].equals("House"))
{
int newAdd = Integer.parseInt(bits[2]);
house[ctr++] = new House(bits[1],newAdd);
}
if(bits[0].equals("Agent"))
{
agent[ctr++] = new Agent(bits[1]);
}
}

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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nick Allen:

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 ]
 
Nick Allen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(...) 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 ]
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nick Allen:
where are the useful people.


I answered your last question with great detail. Flaming me will not get your assignment done. If you do not understand the assignment you should speak with your instructor.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

Which methods work? Which methods don't work? What are "other methods"?
What doesn't work about them? Do they compile? Do they run? Do they give you the wrong result?

PS. Code tags are helpful.
[ November 13, 2003: Message edited by: Marilyn de Queiroz ]
 
Nick Allen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Nick Allen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You neede an instance variable in either the agent or house class in order that either each house knows who its agent is, or each agent knows what houses are his.
 
Trailboss
Posts: 23773
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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."
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Nick Allen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can look at the Arrays class sort methods. Also take a look at the Comparator class.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to implement your own sorting routnie and you're not particularly worried about performance, the bubble sort is a classic sorting algorithm that is fairly simple to implement. If you don't feel like doing that, there's always the Arrays.sort(...) methods, although you will have to learn about implementing your own Comparators in order to use it, or make your objects Comparable.
 
reply
    Bookmark Topic Watch Topic
  • New Topic