Hey all I need a bit of help if someone can!

im writing(trying to!) a small application for a friend who owns a computer repair shop.
Its a 'booking in' application. Someone brings a computer/device in and whover is on the front desk takes some details. Name, Street, Town, Postcode and Phone, these are all seperate JTextFields which get put into a TreeMap with Nameas the key and Street, Town, Postcode and Phone put into a Set and that Set put into the Map as the value.
There is also a Notes JTextArea that is for the operator to type notes on the repair problem.
For each cusomer name in the Map I want to store the notes as well as the address but i also want each set of Notes to be referrencedby a unique number,, as a ccustomer may have 2 or more devices in for repair at the same time. Andd the owner also needs to be able to type in a customers name and see all the repairs linked to that customer and delete solved repairs as needed.

This sounded easy, but its proving other wise.

Thanks for any help at all
Glen....

Start with a Customer class with fields for name, street etc rather than an unstructured set.
Then create Repair class that has fields for Customer, device, notes (etc)

You will find that the application will then be pretty easy to structure using those two main components.

Thanks for the reply James!

I have a DeskApp class to process all the GUI stuff, am I right in saying that it will hold a Map with Customer objects as keys and List or Set of Repair objects as values?

Edited 4 Years Ago by GlenRogers

You could do that. I would just have a List of Customers (or maybe a Map with customer.name as the key, and the whole Customer object as the value, so it's easy to find the right customer), and in each customer I would have it's own list of Repairs as an field.

Thanks for gtaking the time to reply again James. I will try that out!....................

Now I have a Customer object with the attributes name, street,town, postcode and phone. When I print the Custtomer object it prints rbdeskapp.Customer@1855af5 instead of the atribute values. I know I need to override toString() but i can't seem to get it working!
Any tips?

I need to override toString() but i can't seem to get it working!

Post the code you are having problems with.

This is my method to give the attributes of my Customer object(cust) values, the puts cust.nameText() as a key into a TreeMap(customerDetails) and the Customer object (cust) as the value. Then it is supposed to print out the map.

private void processSave()
    {
        cust.setName(nameText.getText());
        cust.setStreet(streetText.getText());
        cust.setTown(townText.getText());
        cust.setPost(postText.getText());
        cust.setPhone(phoneText.getText());

        customerDetails.put(nameText.getText(), cust);
        System.out.println(customerDetails.toString());
    }

This is what I have done for my override of toString()

public String toString()
     {
         return cust.getStreet() + cust.getTown() + cust.getPost() + cust.getPhone();
     }

And this is the output it gives me

{glen=rbdeskapp.Customer@181afa3}

Where does the "glen=" come from? I do not see it in the toString() method.
What class is the toString() method you posted in?

Looks like a problem with your toString - it should be in the Customer class, and look like
return getStreet() + getTown() ...
so it gives details of the current Customer instance

Glen is the name which is th key in the map.
The toString() method is in th same class as the processSave() method I posted. Should it be in the Customer class?

Yes - it provides the default way to display a single instance of a Customer, so it's an instance method of the Customer class.

Than you so much, that did it!

Now I can get on a bit further. This topic is not solved yet, I willl be back!
Glen..

Hi again, I havent done much of this since I was last here.
Can anyone help me in printing a map so that each key/vlue pair is on a seperate line?
Thanks
Glen..

Please post a small simple program that shows the problem that you are having.
The println() method will cause the next thing printed to be on a new line.
The "\n" character will cause what follows it to go on a new line.

There's a method that returns all the keys in a map. Use it to loop through all the keys, printing each key and its corresponding value.

I'm trying to print a maps details, each key/value pair on a seperate line. I need to print to a JTextArea.
Ikind of have it,, but it prints all on one line?

 private void processFind()
    {
        Set<String> customerSet = customerDetails.keySet();
        Object[]customerArray = customerSet.toArray();
        for(int i = 0; i < customerArray.length; i++)
        {
            notes.append(customerArray[i] + "" + customerDetails.get(customerArray[i])
                          + newline);
        }
    }

notes is the JTextArea it prints to and newline has been initialized in the constructor like so

String newline = System.getProperty("line.seperator");

the output I'm getting to my JTextArea notes is like this

"Name: bob hope Address:somestreet, sometown, somepost, 07001100nullName: glen rogeers Address:somestreet, sometown, somepost, 07001100nullName: zak man Address:somestreet, sometown, somepost, 07001100null"

It's giving me null instead of a new line?

Cheers

Glen..

Check your spelling of the property's name. Execute this to get a list of properties:

        Properties props = System.getProperties();
        props.list(System.out);

Edited 4 Years Ago by NormR1

Apart from the speling mstake on the system property, your loop code is OK, but just for your info, it can be coded much more simply with a for-each loop, eg

for (String s : customerDetails.keySet() ) {
    notes.append(s + ": " + customerDetails.get(s) + newline);
}

Brilliant! I had spelt sparator wrong!!!!
Thank you very much.
I will keep tis thread open as I will need guidance again.
Glen..

I will keep tis thread open as I will need guidance again.

Other people who have Java problems will search the topic heading and descriptions to look for known solutions. If you keep posting different problems in the same thread then you make indexing and searching them difficult for others. When your original problem has been solved please mark it "solved" and start a new thread for any new problems. That way you help make a valuable contribution to the DaniWeb knowledge base. Thank you.

Ah I see. Not quite there yet anyway, but once I solve my origional problem I will mark this thread solved!
Thanks
Glen

Ok so this is my processFind() method now

private void processFind()
    {
        for (Object s : customerDetails.keySet()) 
        {
              notes.append(s + ": " + customerDetails.get(s) + newline);
        }
    }

changed to a for each loop(thanks for that)

the only problem is that it is printing the address detail of the last entry on all entries like so:

Name: bob: Address:jimsstreet, jimstown, jimspostcode, jimsphone
Name: glen: Address:jimsstreet, jimstown, jimspostcode, jimsphone
Name: jim: Address:jimsstreet, jimstown, jimspostcode, jimsphone

Any idea why?

Thanks
Glen

It looks like you are putting "jims" at the start of all the Strings.
Where do you build those Strings that show the problem? I do NOT see the Strings: "Name:" or "Address:" in what you posted

Sorry.
This is printing the attributes of a Customer object.
Here is my Customer class.

package rbdeskapp;

import java.util.*;
/**
 *
 * @author user
 */
public class Customer 
{
    private String name;
    private String street;
    private String town;
    private String post;
    private String phone;
    List repairs;

    public Customer(String aName, String aStreet, String aTown, String aPost, String aPhone)
    {
        name = aName;
        street = aStreet;
        town = aTown;
        post = aPost;
        phone = aPhone;

        repairs = new ArrayList<Repair>();
    }

    public String getName()
    {
        return name;
    }

    public String getStreet()
    {
        return street;
    }

    public String getTown()
    {
        return town;
    }

    public String getPost()
    {
        return post;
    }

    public String getPhone()
    {
        return phone;
    }

    public List getRepairs()
    {
        return repairs;
    }

    public void setName(String aName)
    {
        this.name = aName;
    }

    public void setStreet(String aStreet)
    {
        this.street = aStreet;
    }

    public void setTown(String aTown)
    {
        this.town = aTown;
    }

    public void setPost(String aPost)
    {
        this.post = aPost;
    }

    public void setPhone(String aPhone)
    {
        this.phone = aPhone;
    }

    public String toString()
     {
         return "Address:" +  this.getStreet() + ", " + this.getTown() + ", " 
                 + this.getPost() + ", " + this.getPhone();
     }
 }

i hope this makes it clearer
Thanks

"Name:" was a string I put into the map with the name string, like this

private void processSave()
    {
        String name1 = cust.getName();
        cust.setName(nameText.getText());
        cust.setStreet(streetText.getText());
        cust.setTown(townText.getText());
        cust.setPost(postText.getText());
        cust.setPhone(phoneText.getText());

        if(customerDetails.containsKey(name1))
        {
            System.out.println("Customer already exists in database");
        }
        else
        {
            customerDetails.put("Name: " + nameText.getText(), cust);
         }

But I have taken it out now as later I need to search the map baseed on name keys, the String "Name:" gets in the way.
As for "jims", I have text boxes to enter the Strings for Street, Town, Postcode and Phone.
For Bob I had entered bobsstreet, bobstown, bobspost, bobsphone.
Is this any clearer? I could paste all my code so far if you llike?
Thanks
Glen

So "jims" is a valid prefix String for some of the data for one customer.
You never explained what was wrong with the output that you posted:

Name: bob: Address:jimsstreet, jimstown, jimspostcode, jimsphone
Name: glen: Address:jimsstreet, jimstown, jimspostcode, jimsphone
Name: jim: Address:jimsstreet, jimstown, jimspostcode, jimsphone

One way to get that kind of a report is if the code is using static variables to hold the data. The data variables would hold the values of the last thing assigned to it. Earlier values would have been replaced.

The other common way to get this output is to reuse a class object instead of creating a new one for the new data. The collection ends up with a bunch of pointers that all point to the same object instead of each pointing to their own object.

Edited 4 Years Ago by NormR1: Reused vs new object

This question has already been answered. Start a new discussion instead.