Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36446 > unrolled thread

hash map

Started bypablo <pa24959122@gmail.com>
First post2017-04-16 11:53 -0700
Last post2017-04-18 20:05 -0400
Articles 20 on this page of 27 — 6 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  hash map pablo <pa24959122@gmail.com> - 2017-04-16 11:53 -0700
    Re: hash map Martin Gregorie <martin@address-in-sig.invalid> - 2017-04-16 19:10 +0000
    Re:hash map omegajunior <omegajunior@protonmail.com> - 2017-04-16 17:11 -0400
      Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 04:31 -0700
    Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-17 05:11 -0700
      Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 05:32 -0700
        Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-17 05:58 -0700
        Re: hash map Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-04-17 09:10 -0400
          Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 06:53 -0700
            Re: hash map Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-04-17 10:15 -0400
              Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 07:25 -0700
                Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-17 07:46 -0700
                Re: hash map Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-04-17 10:54 -0400
                  Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 08:29 -0700
                    Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-17 08:44 -0700
                    Re: hash map Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-04-17 12:07 -0400
                      Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 09:32 -0700
                        Re: hash map Martin Gregorie <martin@address-in-sig.invalid> - 2017-04-17 23:14 +0000
                          Re: hash map Arne Vajhøj <arne@vajhoej.dk> - 2017-04-17 20:22 -0400
                            Re: hash map Martin Gregorie <martin@address-in-sig.invalid> - 2017-04-18 01:20 +0000
                              Re: hash map Arne Vajhøj <arne@vajhoej.dk> - 2017-04-18 20:01 -0400
                                Re: hash map Martin Gregorie <martin@address-in-sig.invalid> - 2017-04-19 09:02 +0000
                            Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-18 04:54 -0700
                              Re: hash map Arne Vajhøj <arne@vajhoej.dk> - 2017-04-18 20:03 -0400
                                Re: hash map Martin Gregorie <martin@address-in-sig.invalid> - 2017-04-19 08:55 +0000
                                Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-19 04:45 -0700
                              Re: hash map Arne Vajhøj <arne@vajhoej.dk> - 2017-04-18 20:05 -0400

Page 1 of 2  [1] 2  Next page →


#36446 — hash map

Frompablo <pa24959122@gmail.com>
Date2017-04-16 11:53 -0700
Subjecthash map
Message-ID<9a86c6fb-ae40-4acd-902f-afff0ab60fd6@googlegroups.com>
hi all i am trying to add to a hash map but i cant seem to do it could somebody look at the code and tell me why the hell i cant add the key and value 

import java.util.*;
/**
 * The class Garage is used to hold data about a collection of customers. 
 * 
 * @author M250 module team
 * @version 1.0
 */
public class Garage
{
   //garage creating an empty instance of map map 
   private  Map<String,Customer> Customer = new HashMap<String, Customer>();
   

   public Garage() 
   {
     Customer = new HashMap<>(); 
   }
   
   public void addCustomer(String Customer)
   {"
      Customer.Put(Andrew Smith, address 1 The High Street", area 1, "123ABC");
}  

[toc] | [next] | [standalone]


#36447

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2017-04-16 19:10 +0000
Message-ID<od0fj0$fes$1@dont-email.me>
In reply to#36446
On Sun, 16 Apr 2017 11:53:43 -0700, pablo wrote:

> hi all i am trying to add to a hash map but i cant seem to do it could
> somebody look at the code and tell me why the hell i cant add the key
> and value
> 
> import java.util.*;
> /**
>  * The class Garage is used to hold data about a collection of
>  customers.
>  *
>  * @author M250 module team * @version 1.0 */
> public class Garage {
>    //garage creating an empty instance of map map private 
>    Map<String,Customer> Customer = new HashMap<String, Customer>();
>    
>    
>    public Garage()
>    {
>      Customer = new HashMap<>();
>    }
>    
>    public void addCustomer(String Customer)
>    {"
>       Customer.Put(Andrew Smith, address 1 The High Street", area 1,
>       "123ABC");
> }

I see three problems:

1) since you've declared an instance of HashMap<String,Customer> as a 
private instance, why are you trying to replace it in in a Constructor?

2) What are you trying two achieve by using three different class types 
in the two statements?

3) Why are you trying to use a non-existent method in your add() method 
and what, exactly are you trying to store on the Customer map? 
If you haven't downloaded the documentation for the standard Class 
library yet, do so, bookmark it in your web browser and use it when 
you're writing code. Having the class definitions and tutorials available
will help you a lot.
 
4) Some other points to think about and check in whatever text you're
   learning Java from:
   - don't capitalise the first name of a variable or method name. Names
     starting with a capital should only be used for class names.
   - try putting your string delimiters in the right places
   - balance your curly brackets: EVERY { needs a closing } and
     if you always put opening and closing brackets at the same indent
     you'll find making them match gets easier.

  
-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

[toc] | [prev] | [next] | [standalone]


#36450

Fromomegajunior <omegajunior@protonmail.com>
Date2017-04-16 17:11 -0400
Message-ID<od0mla$15dm$1@gioia.aioe.org>
In reply to#36446
pablo <pa24959122@gmail.com> Wrote in message:
> hi all i am trying to add to a hash map but i cant seem to do it could somebody look at the code and tell me why the hell i cant add the key and value 
> 
> import java.util.*;
> /**
>  * The class Garage is used to hold data about a collection of customers. 
>  * 
>  * @author M250 module team
>  * @version 1.0
>  */
> public class Garage
> {
>    //garage creating an empty instance of map map 
>    private  Map<String,Customer> Customer = new HashMap<String, Customer>();
>    
> 
>    public Garage() 
>    {
>      Customer = new HashMap<>(); 
>    }
>    
>    public void addCustomer(String Customer)
>    {"
>       Customer.Put(Andrew Smith, address 1 The High Street", area 1, "123ABC");
> }  
> 

1. You seem to have got your structures wrong. What you're adding
 to the Customer map is <Name, Address>, but instead of Address
 you've defined Customer to contain Customer. If that doesn't
 confuse you, I applaud your mental prowess. 
  
2. Your code doesn't put a String and an Address into the map.
 That's because your code doesn't wrap the customer's name in
 quotes. Leaving out the quotes makes Java interpret the name as a
 Java language keyword or a class or variabla name, which probably
 isn't your intent. 
  
3. Your code uses a Map#Put method. The Map class doesn't have a
 method named Put. It's named put. Note the lower-cased
 p.
  
Combining that, this should work: 
  
final class mine {

private final map<String, String> customers = new HashMap<>(); 

public final void add() {
  this.customers.put("Andrew Smith", "1 The High Street, area 1,
 123ABC");
}

}

If you want the customers map to hold an Address type rather than
 a String containing address data, you'll have to define an
 Address class, first.
  
Does that help?
-- 
We make software better.


----Android NewsGroup Reader----
http://usenet.sinaapp.com/

[toc] | [prev] | [next] | [standalone]


#36452

Frompablo <pa24959122@gmail.com>
Date2017-04-17 04:31 -0700
Message-ID<e7980823-ffc0-4905-836d-ac1dcf01d2e3@googlegroups.com>
In reply to#36450
On Sunday, 16 April 2017 22:11:16 UTC+1, omegajunior  wrote:
> pablo <pa24959122@gmail.com> Wrote in message:
> > hi all i am trying to add to a hash map but i cant seem to do it could somebody look at the code and tell me why the hell i cant add the key and value 
> > 
> > import java.util.*;
> > /**
> >  * The class Garage is used to hold data about a collection of customers. 
> >  * 
> >  * @author M250 module team
> >  * @version 1.0
> >  */
> > public class Garage
> > {
> >    //garage creating an empty instance of map map 
> >    private  Map<String,Customer> Customer = new HashMap<String, Customer>();
> >    
> > 
> >    public Garage() 
> >    {
> >      Customer = new HashMap<>(); 
> >    }
> >    
> >    public void addCustomer(String Customer)
> >    {"
> >       Customer.Put(Andrew Smith, address 1 The High Street", area 1, "123ABC");
> > }  
> > 
> 
> 1. You seem to have got your structures wrong. What you're adding
>  to the Customer map is <Name, Address>, but instead of Address
>  you've defined Customer to contain Customer. If that doesn't
>  confuse you, I applaud your mental prowess. 
>   
> 2. Your code doesn't put a String and an Address into the map.
>  That's because your code doesn't wrap the customer's name in
>  quotes. Leaving out the quotes makes Java interpret the name as a
>  Java language keyword or a class or variabla name, which probably
>  isn't your intent. 
>   
> 3. Your code uses a Map#Put method. The Map class doesn't have a
>  method named Put. It's named put. Note the lower-cased
>  p.
>   
> Combining that, this should work: 
>   
> final class mine {
> 
> private final map<String, String> customers = new HashMap<>(); 
> 
> public final void add() {
>   this.customers.put("Andrew Smith", "1 The High Street, area 1,
>  123ABC");
> }
> 
> }
> 
> If you want the customers map to hold an Address type rather than
>  a String containing address data, you'll have to define an
>  Address class, first.
>   
> Does that help?
> -- 
> We make software better.
> 
> 
> ----Android NewsGroup Reader----
> http://usenet.sinaapp.com/

not really i am trying to add a key this will be a string and the customer will be the value of the data i want to store in the hash map 

[toc] | [prev] | [next] | [standalone]


#36454

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-04-17 05:11 -0700
Message-ID<208075f0-0022-4996-b2b7-a3b90f6c85a6@googlegroups.com>
In reply to#36446
On Sunday, April 16, 2017 at 2:54:02 PM UTC-4, pablo wrote:
> hi all i am trying to add to a hash map but i cant seem to do it could somebody look at the code and tell me why the hell i cant add the key and value 
> 
> import java.util.*;
> /**
>  * The class Garage is used to hold data about a collection of customers. 
>  * 
>  * @author M250 module team
>  * @version 1.0
>  */
> public class Garage
> {
>    //garage creating an empty instance of map map 
>    private  Map<String,Customer> Customer = new HashMap<String, Customer>();
>    
> 
>    public Garage() 
>    {
>      Customer = new HashMap<>(); 
>    }
>    
>    public void addCustomer(String Customer)
>    {"
>       Customer.Put(Andrew Smith, address 1 The High Street", area 1, "123ABC");
> }

https://docs.oracle.com/javase/tutorial/collections/interfaces/map.html
https://www.tutorialspoint.com/java/java_hashmap_class.htm
http://beginnersbook.com/2013/12/hashmap-in-java-with-example/

[toc] | [prev] | [next] | [standalone]


#36456

Frompablo <pa24959122@gmail.com>
Date2017-04-17 05:32 -0700
Message-ID<25389b66-b30f-4076-8f8e-4bfeb91dbc6f@googlegroups.com>
In reply to#36454
On Monday, 17 April 2017 13:11:35 UTC+1, Eric Douglas  wrote:
> On Sunday, April 16, 2017 at 2:54:02 PM UTC-4, pablo wrote:
> > hi all i am trying to add to a hash map but i cant seem to do it could somebody look at the code and tell me why the hell i cant add the key and value 
> > 
> > import java.util.*;
> > /**
> >  * The class Garage is used to hold data about a collection of customers. 
> >  * 
> >  * @author M250 module team
> >  * @version 1.0
> >  */
> > public class Garage
> > {
> >    //garage creating an empty instance of map map 
> >    private  Map<String,Customer> Customer = new HashMap<String, Customer>();
> >    
> > 
> >    public Garage() 
> >    {
> >      Customer = new HashMap<>(); 
> >    }
> >    
> >    public void addCustomer(String Customer)
> >    {"
> >       Customer.Put(Andrew Smith, address 1 The High Street", area 1, "123ABC");
> > }
> 
> https://docs.oracle.com/javase/tutorial/collections/interfaces/map.html
> https://www.tutorialspoint.com/java/java_hashmap_class.htm
> http://beginnersbook.com/2013/12/hashmap-in-java-with-example/

 private  Map<String,String> map = new HashMap<String, String>();
   map.put("Andrew Smith, address 1 The High Street, area 1");

my compiler keeps saying <identifier> expected 

[toc] | [prev] | [next] | [standalone]


#36457

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-04-17 05:58 -0700
Message-ID<ad924bef-c208-4318-b746-64ddec3790be@googlegroups.com>
In reply to#36456
On Monday, April 17, 2017 at 8:32:24 AM UTC-4, pablo wrote:
> On Monday, 17 April 2017 13:11:35 UTC+1, Eric Douglas  wrote:
> > On Sunday, April 16, 2017 at 2:54:02 PM UTC-4, pablo wrote:
> > > hi all i am trying to add to a hash map but i cant seem to do it could somebody look at the code and tell me why the hell i cant add the key and value 
> > > 
> > > import java.util.*;
> > > /**
> > >  * The class Garage is used to hold data about a collection of customers. 
> > >  * 
> > >  * @author M250 module team
> > >  * @version 1.0
> > >  */
> > > public class Garage
> > > {
> > >    //garage creating an empty instance of map map 
> > >    private  Map<String,Customer> Customer = new HashMap<String, Customer>();
> > >    
> > > 
> > >    public Garage() 
> > >    {
> > >      Customer = new HashMap<>(); 
> > >    }
> > >    
> > >    public void addCustomer(String Customer)
> > >    {"
> > >       Customer.Put(Andrew Smith, address 1 The High Street", area 1, "123ABC");
> > > }
> > 
> > https://docs.oracle.com/javase/tutorial/collections/interfaces/map.html
> > https://www.tutorialspoint.com/java/java_hashmap_class.htm
> > http://beginnersbook.com/2013/12/hashmap-in-java-with-example/
> 
>  private  Map<String,String> map = new HashMap<String, String>();
>    map.put("Andrew Smith, address 1 The High Street, area 1");
> 
> my compiler keeps saying <identifier> expected

Read the tutorials.
put requires 2 parameters, a key and a value.  You passed it one.

[toc] | [prev] | [next] | [standalone]


#36458

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2017-04-17 09:10 -0400
Message-ID<od2ena$sf8$1@dont-email.me>
In reply to#36456
On 4/17/2017 8:32 AM, pablo wrote:
> On Monday, 17 April 2017 13:11:35 UTC+1, Eric Douglas  wrote:
>> On Sunday, April 16, 2017 at 2:54:02 PM UTC-4, pablo wrote:
>>> hi all i am trying to add to a hash map but i cant seem to do it could somebody look at the code and tell me why the hell i cant add the key and value
>>>
>>> import java.util.*;
>>> /**
>>>   * The class Garage is used to hold data about a collection of customers.
>>>   *
>>>   * @author M250 module team
>>>   * @version 1.0
>>>   */
>>> public class Garage
>>> {
>>>     //garage creating an empty instance of map map
>>>     private  Map<String,Customer> Customer = new HashMap<String, Customer>();
>>>     
>>>
>>>     public Garage()
>>>     {
>>>       Customer = new HashMap<>();
>>>     }
>>>     
>>>     public void addCustomer(String Customer)
>>>     {"
>>>        Customer.Put(Andrew Smith, address 1 The High Street", area 1, "123ABC");
>>> }
>>
>> https://docs.oracle.com/javase/tutorial/collections/interfaces/map.html
>> https://www.tutorialspoint.com/java/java_hashmap_class.htm
>> http://beginnersbook.com/2013/12/hashmap-in-java-with-example/
> 
>   private  Map<String,String> map = new HashMap<String, String>();
>     map.put("Andrew Smith, address 1 The High Street, area 1");
> 
> my compiler keeps saying <identifier> expected

     Are you certain that what you've shown us is exactly the same code
you gave to the compiler?  My compiler also complains, but not about a
missing <identifier>.  Instead, I get a flurry of ten complaints about
"unclosed string literal" and "illegal start of expression" and "not a
statement" and so on, all concerning the botched final three lines.
(Other errors are apparent to my eye, but I imagine the compiler gave
up before its analysis got that far.)

     Please re-check your source code, and post *exactly* what you gave
to the compiler (and *exactly* what the compiler said in reply).  If we
must guess about what the code looks like, we'll wind up debugging our
guesses for you instead of debugging your code.

-- 
esosman@comcast-dot-net.invalid
Thirteen hundred seventy-four days to go.

[toc] | [prev] | [next] | [standalone]


#36460

Frompablo <pa24959122@gmail.com>
Date2017-04-17 06:53 -0700
Message-ID<fe8a759e-1df6-4d5d-beb8-44e49ae00e83@googlegroups.com>
In reply to#36458
On Monday, 17 April 2017 14:11:08 UTC+1, Eric Sosman  wrote:
> On 4/17/2017 8:32 AM, pablo wrote:
> > On Monday, 17 April 2017 13:11:35 UTC+1, Eric Douglas  wrote:
> >> On Sunday, April 16, 2017 at 2:54:02 PM UTC-4, pablo wrote:
> >>> hi all i am trying to add to a hash map but i cant seem to do it could somebody look at the code and tell me why the hell i cant add the key and value
> >>>
> >>> import java.util.*;
> >>> /**
> >>>   * The class Garage is used to hold data about a collection of customers.
> >>>   *
> >>>   * @author M250 module team
> >>>   * @version 1.0
> >>>   */
> >>> public class Garage
> >>> {
> >>>     //garage creating an empty instance of map map
> >>>     private  Map<String,Customer> Customer = new HashMap<String, Customer>();
> >>>     
> >>>
> >>>     public Garage()
> >>>     {
> >>>       Customer = new HashMap<>();
> >>>     }
> >>>     
> >>>     public void addCustomer(String Customer)
> >>>     {"
> >>>        Customer.Put(Andrew Smith, address 1 The High Street", area 1, "123ABC");
> >>> }
> >>
> >> https://docs.oracle.com/javase/tutorial/collections/interfaces/map.html
> >> https://www.tutorialspoint.com/java/java_hashmap_class.htm
> >> http://beginnersbook.com/2013/12/hashmap-in-java-with-example/
> > 
> >   private  Map<String,String> map = new HashMap<String, String>();
> >     map.put("Andrew Smith, address 1 The High Street, area 1");
> > 
> > my compiler keeps saying <identifier> expected
> 
>      Are you certain that what you've shown us is exactly the same code
> you gave to the compiler?  My compiler also complains, but not about a
> missing <identifier>.  Instead, I get a flurry of ten complaints about
> "unclosed string literal" and "illegal start of expression" and "not a
> statement" and so on, all concerning the botched final three lines.
> (Other errors are apparent to my eye, but I imagine the compiler gave
> up before its analysis got that far.)
> 
>      Please re-check your source code, and post *exactly* what you gave
> to the compiler (and *exactly* what the compiler said in reply).  If we
> must guess about what the code looks like, we'll wind up debugging our
> guesses for you instead of debugging your code.
> 
> -- 
> esosman@comcast-dot-net.invalid
> Thirteen hundred seventy-four days to go.

import java.util.*;
/**
 * The class Garage is used to hold data about a collection of customers. 
 * 
 * @author M250 module team
 * @version 1.0
 */
public class Garage
{
   //garage creating an empty instance of map map 
   private  Map<String,String> map = new HashMap<String, String>();
   map.put("Andrew Smith, address 1 The High Street, area 1");
   

   
}  

[toc] | [prev] | [next] | [standalone]


#36463

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2017-04-17 10:15 -0400
Message-ID<od2ifk$98s$1@dont-email.me>
In reply to#36460
On 4/17/2017 9:53 AM, pablo wrote:
> 
> import java.util.*;
> /**
>   * The class Garage is used to hold data about a collection of customers.
>   *
>   * @author M250 module team
>   * @version 1.0
>   */
> public class Garage
> {
>     //garage creating an empty instance of map map
>     private  Map<String,String> map = new HashMap<String, String>();

     Okay: This says that each "Garage" instance owns a Map whose
keys are Strings and whose corresponding values are also Strings,
and it arranges to create such a Map (empty) each time you create
a Garage.  Fine so far.

>     map.put("Andrew Smith, address 1 The High Street, area 1");

     ... but this is, er, "less fine."  For one thing, it's not a
declaration but an executable statement, a call upon the Map's put()
method.  Executable statements can't just float around in the ether,
but must be inside methods or constructors (or static blocks, but
they are less common).

     After you've solved that problem by finding a suitable home for
the executable statement, you'll discover another one: Map's put()
method requires two arguments, the key and corresponding value of a
key/value pair.  The method call you have written provides only one
argument, not the required two.  Perhaps you meant something like

	map.put("Andrew Smith", "1 The High Street, area 1");

... which associates the key "Andrew Smith" with the value "1 The
High Street, area 1".  That's just a guess, though, because we don't
know what relationship this map is intended to represent.

> 
>     
> }
> 


-- 
esosman@comcast-dot-net.invalid
Thirteen hundred seventy-four days to go.

[toc] | [prev] | [next] | [standalone]


#36468

Frompablo <pa24959122@gmail.com>
Date2017-04-17 07:25 -0700
Message-ID<8a53e56c-5877-4c31-976f-5802f926f44a@googlegroups.com>
In reply to#36463
On Monday, 17 April 2017 15:15:18 UTC+1, Eric Sosman  wrote:
> On 4/17/2017 9:53 AM, pablo wrote:
> > 
> > import java.util.*;
> > /**
> >   * The class Garage is used to hold data about a collection of customers.
> >   *
> >   * @author M250 module team
> >   * @version 1.0
> >   */
> > public class Garage
> > {
> >     //garage creating an empty instance of map map
> >     private  Map<String,String> map = new HashMap<String, String>();
> 
>      Okay: This says that each "Garage" instance owns a Map whose
> keys are Strings and whose corresponding values are also Strings,
> and it arranges to create such a Map (empty) each time you create
> a Garage.  Fine so far.
> 
> >     map.put("Andrew Smith, address 1 The High Street, area 1");
> 
>      ... but this is, er, "less fine."  For one thing, it's not a
> declaration but an executable statement, a call upon the Map's put()
> method.  Executable statements can't just float around in the ether,
> but must be inside methods or constructors (or static blocks, but
> they are less common).
> 
>      After you've solved that problem by finding a suitable home for
> the executable statement, you'll discover another one: Map's put()
> method requires two arguments, the key and corresponding value of a
> key/value pair.  The method call you have written provides only one
> argument, not the required two.  Perhaps you meant something like
> 
> 	map.put("Andrew Smith", "1 The High Street, area 1");
> 
> ... which associates the key "Andrew Smith" with the value "1 The
> High Street, area 1".  That's just a guess, though, because we don't
> know what relationship this map is intended to represent.
> 
> > 
> >     
> > }
> > 
> 
> 
> -- 
> esosman@comcast-dot-net.invalid
> Thirteen hundred seventy-four days to go.

hi Eric just to put a little bit of context to this this is what i have been asked to do obviously i am struggling 

 An instance of Garage is used to hold data about a collection of customers. Declare a private instance variable called customers in your Garage class, capable of referencing a map where the keys are strings and the values are Customer objects as below (the order of keys in the map is unimportant):
Key       Value
 "123ABC" Customer object with name "Andrew Smith", address "1 The High Street", area 1
 "456DEF" Customer object with name "Janet Jones", address "145 Main Street", area 1 
"789GHI" Customer object with name "Christine Charter", address "50 Lake View", area 2

[toc] | [prev] | [next] | [standalone]


#36470

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-04-17 07:46 -0700
Message-ID<222508d4-b01f-4f73-8888-6aae1a22a3b7@googlegroups.com>
In reply to#36468
On Monday, April 17, 2017 at 10:25:30 AM UTC-4, pablo wrote:
> hi Eric just to put a little bit of context to this this is what i have been asked to do obviously i am struggling 
> 
>  An instance of Garage is used to hold data about a collection of customers. Declare a private instance variable called customers in your Garage class, capable of referencing a map where the keys are strings and the values are Customer objects as below (the order of keys in the map is unimportant):
> Key       Value
>  "123ABC" Customer object with name "Andrew Smith", address "1 The High Street", area 1
>  "456DEF" Customer object with name "Janet Jones", address "145 Main Street", area 1 
> "789GHI" Customer object with name "Christine Charter", address "50 Lake View", area 2

If you're in a beginner course and don't understand the basics of the language, you should ask the teacher.
If you have a more specific problem we could certainly help you figure that out.
While those instructions are a little vague and I could write that a few different ways and consider it "correct", and you need to be able to write your own code from scratch and understand it if you're going to be successful, here's a sample to study.

public class Garage {
     // garage creating an empty instance of map
     private Map<String, Customer> customer = new HashMap();

     public static void main(String[] args) {
          Garage g1 = new Garage();
          Customer c1 = new Customer();
          c1.setName("Andrew Smith");
          c1.setAddress("1 The High Street");
          c1.setArea(1);
          g1.addCustomer("123ABC", c1);
          Customer c2 = new Customer();
          c2.setName("Janet Jones");
          c2.setAddress("145 Main Street");
          c2.setArea(1);
          g1.addCustomer("456DEF", c2);
          Customer c3 = new Customer();
          c3.setName("Christine Charter");
          c3.setAddress("50 Lake View");
          c3.setArea(2);
          g1.addCustomer("789GHI", c3);
          System.out.println("test complete");
     }
     public void addCustomer(String newkey, Customer newcust) {
          customer.put(newkey,newcust);
     }
     public Customer getCustomer(String key) {
          return customer.get(key);
     }
     public static class Customer {
          private String name;
          private String address;
          private int area;
          public String getName() {
               return name;
          }
          public String getAddress() {
               return address;
          }
          public int getArea() {
               return area;
          }
          public void setName(String newname) {
               name = newname;
          }
          public void setAddress(String newaddress) {
               address = newaddress;
          }
          public void setArea(int newarea) {
               area = newarea;
          }
     }
}

[toc] | [prev] | [next] | [standalone]


#36471

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2017-04-17 10:54 -0400
Message-ID<od2koi$gie$1@dont-email.me>
In reply to#36468
On 4/17/2017 10:25 AM, pablo wrote:
> On Monday, 17 April 2017 15:15:18 UTC+1, Eric Sosman  wrote:
>> On 4/17/2017 9:53 AM, pablo wrote:
>>>
>>> import java.util.*;
>>> /**
>>>    * The class Garage is used to hold data about a collection of customers.
>>>    *
>>>    * @author M250 module team
>>>    * @version 1.0
>>>    */
>>> public class Garage
>>> {
>>>      //garage creating an empty instance of map map
>>>      private  Map<String,String> map = new HashMap<String, String>();
>>
>>       Okay: This says that each "Garage" instance owns a Map whose
>> keys are Strings and whose corresponding values are also Strings,
>> and it arranges to create such a Map (empty) each time you create
>> a Garage.  Fine so far.
>>
>>>      map.put("Andrew Smith, address 1 The High Street, area 1");
>>
>>       ... but this is, er, "less fine."  For one thing, it's not a
>> declaration but an executable statement, a call upon the Map's put()
>> method.  Executable statements can't just float around in the ether,
>> but must be inside methods or constructors (or static blocks, but
>> they are less common).
>>
>>       After you've solved that problem by finding a suitable home for
>> the executable statement, you'll discover another one: Map's put()
>> method requires two arguments, the key and corresponding value of a
>> key/value pair.  The method call you have written provides only one
>> argument, not the required two.  Perhaps you meant something like
>>
>> 	map.put("Andrew Smith", "1 The High Street, area 1");
>>
>> ... which associates the key "Andrew Smith" with the value "1 The
>> High Street, area 1".  That's just a guess, though, because we don't
>> know what relationship this map is intended to represent.
>>
>>>
>>>      
>>> }
>>>
>>
>>
>> -- 
>> esosman@comcast-dot-net.invalid
>> Thirteen hundred seventy-four days to go.
> 
> hi Eric just to put a little bit of context to this this is what i have been asked to do obviously i am struggling
> 
>   An instance of Garage is used to hold data about a collection of customers. Declare a private instance variable called customers in your Garage class, capable of referencing a map where the keys are strings and the values are Customer objects as below (the order of keys in the map is unimportant):
> Key       Value
>   "123ABC" Customer object with name "Andrew Smith", address "1 The High Street", area 1
>   "456DEF" Customer object with name "Janet Jones", address "145 Main Street", area 1
> "789GHI" Customer object with name "Christine Charter", address "50 Lake View", area 2

     Okay; that's a bit more for me to work with.  The first thing to
realize is that you need to write *two* classes: One to represent a
Garage, and the other to represent a Customer.  Let's begin with the
latter:

     A Customer has a name, an address, and perhaps an "area" -- it's
not clear to me what the problem's notation signifies.  Perhaps a
Customer has other attributes, too: How many parking spaces he rents,
how much rent is due each month, how badly the account is in arrears,
what telephone number(s) will reach him, and so on -- that's up to
you, or perhaps to the people who have set you the problem (was there,
by chance, a Customer class as the subject of an earlier exercise?).

     At any rate, you need a Customer.java file defining your Customer
class.

     Then you need Garage.java defining Garage.  That class will own a
Map relating the given keys (auto registration plate numbers, perhaps?)
to the associated Customers.  You'll have something like

	public class Garage {
	   ...
	   private Map<String, Customer> customers = new HashMap<>();
	   ...
	}

There are two things to note here, one important and one less so.  The
more important thing is that the values in this map are not Strings,
but Customer objects.  Those Customer objects in turn own Strings to
describe names and addresses and so on, but the Customer objects are
instances of your Customer class.  (The less important thing is the
use of <> on the right-hand side; the compiler already knows from the
left-hand side what should go inside the brackets, so you needn't write
it a second time -- but omitting it is just a handy abbreviation, not
something that changes the meaning in any way.)

     Okay so far?  Then how do you put Customers in a Garage?

     First, you need a Garage:

	Garage pablosGarage = new Garage();

     Next, you need some Customers:

	Customer c1 = new Customer("Andrew Smith", "1 The High Street");
	Customer c2 = new Customer("Janet Jones", "145 Main Street");

     Finally, you need to put the Customers in the Garage -- Oops!  The
Garage's map of keys to Customers is private, and can only be read and
written from inside the Garage class.  So, you need to write a method
that lets "outsiders" add things to a Garage (and probably additional
methods to retrieve what's in there, too):

	public class Garage {
	   ...
	   public void addCustomer(String key, Customer cust) {
	      customers.put(key, cust);
	   }
	   ...
	}

... and then in the "outsider" -- perhaps a Main or Driver class --
where you've set up pablosGarage and c1 and c2 and the rest, you could
write

	pablosGarage.addCustomer("123ABC", c1);
	pablosGarage.addcustomer("456DEF", c2);

... and so on to populate the Garage.

     I imagine the course will go on to have you implement additional
methods for Garage and/or Customer, making the assemblage more useful
by degrees.  Perhaps the Garage's keys will change from simple Strings
to full-fledged Automobile objects, perhaps you will be asked to write
a method to evict non-paying Customers from your Garage, perhaps ...

-- 
esosman@comcast-dot-net.invalid
Thirteen hundred seventy-four days to go.

[toc] | [prev] | [next] | [standalone]


#36472

Frompablo <pa24959122@gmail.com>
Date2017-04-17 08:29 -0700
Message-ID<1bcffbc0-a529-4185-87f2-8e1d66bf319d@googlegroups.com>
In reply to#36471
On Monday, 17 April 2017 15:54:12 UTC+1, Eric Sosman  wrote:
> On 4/17/2017 10:25 AM, pablo wrote:
> > On Monday, 17 April 2017 15:15:18 UTC+1, Eric Sosman  wrote:
> >> On 4/17/2017 9:53 AM, pablo wrote:
> >>>
> >>> import java.util.*;
> >>> /**
> >>>    * The class Garage is used to hold data about a collection of customers.
> >>>    *
> >>>    * @author M250 module team
> >>>    * @version 1.0
> >>>    */
> >>> public class Garage
> >>> {
> >>>      //garage creating an empty instance of map map
> >>>      private  Map<String,String> map = new HashMap<String, String>();
> >>
> >>       Okay: This says that each "Garage" instance owns a Map whose
> >> keys are Strings and whose corresponding values are also Strings,
> >> and it arranges to create such a Map (empty) each time you create
> >> a Garage.  Fine so far.
> >>
> >>>      map.put("Andrew Smith, address 1 The High Street, area 1");
> >>
> >>       ... but this is, er, "less fine."  For one thing, it's not a
> >> declaration but an executable statement, a call upon the Map's put()
> >> method.  Executable statements can't just float around in the ether,
> >> but must be inside methods or constructors (or static blocks, but
> >> they are less common).
> >>
> >>       After you've solved that problem by finding a suitable home for
> >> the executable statement, you'll discover another one: Map's put()
> >> method requires two arguments, the key and corresponding value of a
> >> key/value pair.  The method call you have written provides only one
> >> argument, not the required two.  Perhaps you meant something like
> >>
> >> 	map.put("Andrew Smith", "1 The High Street, area 1");
> >>
> >> ... which associates the key "Andrew Smith" with the value "1 The
> >> High Street, area 1".  That's just a guess, though, because we don't
> >> know what relationship this map is intended to represent.
> >>
> >>>
> >>>      
> >>> }
> >>>
> >>
> >>
> >> -- 
> >> esosman@comcast-dot-net.invalid
> >> Thirteen hundred seventy-four days to go.
> > 
> > hi Eric just to put a little bit of context to this this is what i have been asked to do obviously i am struggling
> > 
> >   An instance of Garage is used to hold data about a collection of customers. Declare a private instance variable called customers in your Garage class, capable of referencing a map where the keys are strings and the values are Customer objects as below (the order of keys in the map is unimportant):
> > Key       Value
> >   "123ABC" Customer object with name "Andrew Smith", address "1 The High Street", area 1
> >   "456DEF" Customer object with name "Janet Jones", address "145 Main Street", area 1
> > "789GHI" Customer object with name "Christine Charter", address "50 Lake View", area 2
> 
>      Okay; that's a bit more for me to work with.  The first thing to
> realize is that you need to write *two* classes: One to represent a
> Garage, and the other to represent a Customer.  Let's begin with the
> latter:
> 
>      A Customer has a name, an address, and perhaps an "area" -- it's
> not clear to me what the problem's notation signifies.  Perhaps a
> Customer has other attributes, too: How many parking spaces he rents,
> how much rent is due each month, how badly the account is in arrears,
> what telephone number(s) will reach him, and so on -- that's up to
> you, or perhaps to the people who have set you the problem (was there,
> by chance, a Customer class as the subject of an earlier exercise?).
> 
>      At any rate, you need a Customer.java file defining your Customer
> class.
> 
>      Then you need Garage.java defining Garage.  That class will own a
> Map relating the given keys (auto registration plate numbers, perhaps?)
> to the associated Customers.  You'll have something like
> 
> 	public class Garage {
> 	   ...
> 	   private Map<String, Customer> customers = new HashMap<>();
> 	   ...
> 	}
> 
> There are two things to note here, one important and one less so.  The
> more important thing is that the values in this map are not Strings,
> but Customer objects.  Those Customer objects in turn own Strings to
> describe names and addresses and so on, but the Customer objects are
> instances of your Customer class.  (The less important thing is the
> use of <> on the right-hand side; the compiler already knows from the
> left-hand side what should go inside the brackets, so you needn't write
> it a second time -- but omitting it is just a handy abbreviation, not
> something that changes the meaning in any way.)
> 
>      Okay so far?  Then how do you put Customers in a Garage?
> 
>      First, you need a Garage:
> 
> 	Garage pablosGarage = new Garage();
> 
>      Next, you need some Customers:
> 
> 	Customer c1 = new Customer("Andrew Smith", "1 The High Street");
> 	Customer c2 = new Customer("Janet Jones", "145 Main Street");
> 
>      Finally, you need to put the Customers in the Garage -- Oops!  The
> Garage's map of keys to Customers is private, and can only be read and
> written from inside the Garage class.  So, you need to write a method
> that lets "outsiders" add things to a Garage (and probably additional
> methods to retrieve what's in there, too):
> 
> 	public class Garage {
> 	   ...
> 	   public void addCustomer(String key, Customer cust) {
> 	      customers.put(key, cust);
> 	   }
> 	   ...
> 	}
> 
> ... and then in the "outsider" -- perhaps a Main or Driver class --
> where you've set up pablosGarage and c1 and c2 and the rest, you could
> write
> 
> 	pablosGarage.addCustomer("123ABC", c1);
> 	pablosGarage.addcustomer("456DEF", c2);
> 
> ... and so on to populate the Garage.
> 
>      I imagine the course will go on to have you implement additional
> methods for Garage and/or Customer, making the assemblage more useful
> by degrees.  Perhaps the Garage's keys will change from simple Strings
> to full-fledged Automobile objects, perhaps you will be asked to write
> a method to evict non-paying Customers from your Garage, perhaps ...
> 
> -- 
> esosman@comcast-dot-net.invalid
> Thirteen hundred seventy-four days to go.

sorry mate this is what i have so far and i am getting an error maybe more but to start with i am getting can not find symbol variable customer. i am using bluej editor

import java.util.*;
/**
 * The class Garage is used to hold data about a collection of customers. 
 * 
 * @author M250 module team
 * @version 1.0
 */
public class Garage 
{
   /**
    * Constructor for objects of class Garage
    */
   public Garage()
   {
     Map<String, Customer> customers = new HashMap<>(); 
   }
   
   public void Garage()
   {
      Garage Garage = new Garage(); 
   }

   public void addCustomer(String key, Customer cust)
   { 
     customer.put("123ABC",  "Andrew Smith, address 1 The High Street, area 1" );
     customer.put("456DEF",  "Janet Jones, address 145 Main Street, area 1");
     customer.put("789GHI",   "Christine Charter, address 50 Lake View, area 2");
   } 
           
} 

the customer class has already been wrote 

[toc] | [prev] | [next] | [standalone]


#36473

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-04-17 08:44 -0700
Message-ID<e2e6ecc5-4fe5-4510-9ad5-ab9c158f80b9@googlegroups.com>
In reply to#36472
On Monday, April 17, 2017 at 11:29:34 AM UTC-4, pablo wrote:
> sorry mate this is what i have so far and i am getting an error maybe more but to start with i am getting can not find symbol variable customer. i am using bluej editor
> 
> import java.util.*;
> /**
>  * The class Garage is used to hold data about a collection of customers. 
>  * 
>  * @author M250 module team
>  * @version 1.0
>  */
> public class Garage 
> {
>    /**
>     * Constructor for objects of class Garage
>     */
>    public Garage()
>    {
>      Map<String, Customer> customers = new HashMap<>(); 
>    }
>    
>    public void Garage()
>    {
>       Garage Garage = new Garage(); 
>    }
> 
>    public void addCustomer(String key, Customer cust)
>    { 
>      customer.put("123ABC",  "Andrew Smith, address 1 The High Street, area 1" );
>      customer.put("456DEF",  "Janet Jones, address 145 Main Street, area 1");
>      customer.put("789GHI",   "Christine Charter, address 50 Lake View, area 2");
>    } 
>            
> } 
> 
> the customer class has already been wrote

Is the Customer class in the same package as the Garage class?  If not, you need an import.
Other than that, there are so many things wrong with your samples, either you are not paying attention in class or you need to have a talk with the teacher.

Do you not understand the concept of a variable and/or scope?
You create a variable customers in the constructor with no further reference. This is declared locally and can only be referenced in the constructor.
You declare variables key and cust on the addCustomer method and don't use them.
You reference a variable customer in the addCustomer which is not declared but appears to be a Map with String keys and String values.
...

[toc] | [prev] | [next] | [standalone]


#36474

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2017-04-17 12:07 -0400
Message-ID<od2p1h$uu7$1@dont-email.me>
In reply to#36472
On 4/17/2017 11:29 AM, pablo wrote:
> 
> sorry mate this is what i have so far and i am getting an error maybe more but to start with i am getting can not find symbol variable customer. i am using bluej editor
> 
> import java.util.*;
> /**
>   * The class Garage is used to hold data about a collection of customers.
>   *
>   * @author M250 module team
>   * @version 1.0
>   */
> public class Garage
> {
>     /**
>      * Constructor for objects of class Garage
>      */
>     public Garage()
>     {
>       Map<String, Customer> customers = new HashMap<>();

     This line declares a variable `customers', creates a new, empty
HashMap, and sets `customers' to point at it.  Fine, but ... how long
does the `customers' variable exist?

>     }

     Only until this point: As soon as the Garage constructor finishes,
all its variables -- including `customers' -- cease to exist.  The
HashMap that was created is now "orphaned," eligible to be collected
as garbage, because nothing in the program refers to it any more.

>     
>     public void Garage()
>     {
>        Garage Garage = new Garage();
>     }

     This method does nothing of any use whatever.

>     public void addCustomer(String key, Customer cust)
>     {
>       customer.put("123ABC",  "Andrew Smith, address 1 The High Street, area 1" );

     First problem: There never is, and never was, a variable anywhere
in your program named `customer'.  Java has absolutely no idea what you
mean when you write `customer' here; you might just as well have written
`genghisKhansGrandmother'.  Naturally, the compiler complains.

     Second problem: If `customer' did in fact refer to a Map associating
Strings with Customers, would this line be correct?  No!  A String is
not a Customer, so you can't supply a String as the value; you need to
supply a Customer.

>       customer.put("456DEF",  "Janet Jones, address 145 Main Street, area 1");
>       customer.put("789GHI",   "Christine Charter, address 50 Lake View, area 2");
>     }
>             
> }
> 
> the customer class has already been wrote

     Long years ago I had a student who approached his programming tasks
by throwing together a mish-mash of half-understood code-like source
lines, pondering the compiler's complaints, and making random change
after random change until he chanced upon something the compiler would
accept in silence.  This code would seldom then do what was intended,
so he'd keep on making herky-jerky changes until it eventually printed
what he thought might be the right answer for one test case, then he'd
hand the result in as his homework.

     I cannot recall that he ever submitted a program that would run a
second test case correctly.  And it's my strong impression that he did
not learn how to program.  He was the student and I the teacher, and
the fault for his lack of learning could lie with either side, but for
selfish reasons I decided the problem was his and not mine.  I put it
down to his tendency to scribble code before he'd really thought about
what he needed to do, in hopes that fixing his compile-time errors would
somehow guide him over the rough bits.

     The compiler is not a tutor.

     The compiler will not do your studying for you.

     The compiler will not teach you how to program.

     I strongly suggest that you start over again at Lesson One, and
resist the temptation to rush into writing code before gaining some
understanding.  It's likely that your experiences so far may help
you get more out of the material a second time around than you did
on the first attempt -- but I sincerely doubt you'll make meaningful
progress with the level of understanding you've demonstrated thus far.

     Study diligently, and good luck!

-- 
esosman@comcast-dot-net.invalid
Thirteen hundred seventy-four days to go.

[toc] | [prev] | [next] | [standalone]


#36475

Frompablo <pa24959122@gmail.com>
Date2017-04-17 09:32 -0700
Message-ID<92da5574-f874-49a4-9a70-492a154f166e@googlegroups.com>
In reply to#36474
On Monday, 17 April 2017 17:07:28 UTC+1, Eric Sosman  wrote:
> On 4/17/2017 11:29 AM, pablo wrote:
> > 
> > sorry mate this is what i have so far and i am getting an error maybe more but to start with i am getting can not find symbol variable customer. i am using bluej editor
> > 
> > import java.util.*;
> > /**
> >   * The class Garage is used to hold data about a collection of customers.
> >   *
> >   * @author M250 module team
> >   * @version 1.0
> >   */
> > public class Garage
> > {
> >     /**
> >      * Constructor for objects of class Garage
> >      */
> >     public Garage()
> >     {
> >       Map<String, Customer> customers = new HashMap<>();
> 
>      This line declares a variable `customers', creates a new, empty
> HashMap, and sets `customers' to point at it.  Fine, but ... how long
> does the `customers' variable exist?
> 
> >     }
> 
>      Only until this point: As soon as the Garage constructor finishes,
> all its variables -- including `customers' -- cease to exist.  The
> HashMap that was created is now "orphaned," eligible to be collected
> as garbage, because nothing in the program refers to it any more.
> 
> >     
> >     public void Garage()
> >     {
> >        Garage Garage = new Garage();
> >     }
> 
>      This method does nothing of any use whatever.
> 
> >     public void addCustomer(String key, Customer cust)
> >     {
> >       customer.put("123ABC",  "Andrew Smith, address 1 The High Street, area 1" );
> 
>      First problem: There never is, and never was, a variable anywhere
> in your program named `customer'.  Java has absolutely no idea what you
> mean when you write `customer' here; you might just as well have written
> `genghisKhansGrandmother'.  Naturally, the compiler complains.
> 
>      Second problem: If `customer' did in fact refer to a Map associating
> Strings with Customers, would this line be correct?  No!  A String is
> not a Customer, so you can't supply a String as the value; you need to
> supply a Customer.
> 
> >       customer.put("456DEF",  "Janet Jones, address 145 Main Street, area 1");
> >       customer.put("789GHI",   "Christine Charter, address 50 Lake View, area 2");
> >     }
> >             
> > }
> > 
> > the customer class has already been wrote
> 
>      Long years ago I had a student who approached his programming tasks
> by throwing together a mish-mash of half-understood code-like source
> lines, pondering the compiler's complaints, and making random change
> after random change until he chanced upon something the compiler would
> accept in silence.  This code would seldom then do what was intended,
> so he'd keep on making herky-jerky changes until it eventually printed
> what he thought might be the right answer for one test case, then he'd
> hand the result in as his homework.
> 
>      I cannot recall that he ever submitted a program that would run a
> second test case correctly.  And it's my strong impression that he did
> not learn how to program.  He was the student and I the teacher, and
> the fault for his lack of learning could lie with either side, but for
> selfish reasons I decided the problem was his and not mine.  I put it
> down to his tendency to scribble code before he'd really thought about
> what he needed to do, in hopes that fixing his compile-time errors would
> somehow guide him over the rough bits.
> 
>      The compiler is not a tutor.
> 
>      The compiler will not do your studying for you.
> 
>      The compiler will not teach you how to program.
> 
>      I strongly suggest that you start over again at Lesson One, and
> resist the temptation to rush into writing code before gaining some
> understanding.  It's likely that your experiences so far may help
> you get more out of the material a second time around than you did
> on the first attempt -- but I sincerely doubt you'll make meaningful
> progress with the level of understanding you've demonstrated thus far.
> 
>      Study diligently, and good luck!
> 
> -- 
> esosman@comcast-dot-net.invalid
> Thirteen hundred seventy-four days to go.

I will take that on board Eric about your old Student and i understand that i shouldn't rush but to be fair i am 40 years of age now and i want to learn this is why i am looking for a tutor aswell 

[toc] | [prev] | [next] | [standalone]


#36481

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2017-04-17 23:14 +0000
Message-ID<od3i84$i6i$1@dont-email.me>
In reply to#36475
On Mon, 17 Apr 2017 09:32:07 -0700, pablo wrote:

> On Monday, 17 April 2017 17:07:28 UTC+1, Eric Sosman  wrote:
>> On 4/17/2017 11:29 AM, pablo wrote:
>> > 
>> > sorry mate this is what i have so far and i am getting an error maybe
>> > more but to start with i am getting can not find symbol variable
>> > customer. i am using bluej editor
>> > 
>> > import java.util.*;
>> > /**
>> >   * The class Garage is used to hold data about a collection of
>> >   customers.
>> >   *
>> >   * @author M250 module team * @version 1.0 */
>> > public class Garage {
>> >     /**
>> >      * Constructor for objects of class Garage */
>> >     public Garage()
>> >     {
>> >       Map<String, Customer> customers = new HashMap<>();
>> 
>>      This line declares a variable `customers', creates a new, empty
>> HashMap, and sets `customers' to point at it.  Fine, but ... how long
>> does the `customers' variable exist?
>> 
>> >     }
>> 
>>      Only until this point: As soon as the Garage constructor finishes,
>> all its variables -- including `customers' -- cease to exist.  The
>> HashMap that was created is now "orphaned," eligible to be collected as
>> garbage, because nothing in the program refers to it any more.
>> 
>> 
>> >     public void Garage()
>> >     {
>> >        Garage Garage = new Garage();
>> >     }
>> 
>>      This method does nothing of any use whatever.
>> 
>> >     public void addCustomer(String key, Customer cust)
>> >     {
>> >       customer.put("123ABC",  "Andrew Smith, address 1 The High
>> >       Street, area 1" );
>> 
>>      First problem: There never is, and never was, a variable anywhere
>> in your program named `customer'.  Java has absolutely no idea what you
>> mean when you write `customer' here; you might just as well have
>> written `genghisKhansGrandmother'.  Naturally, the compiler complains.
>> 
>>      Second problem: If `customer' did in fact refer to a Map
>>      associating
>> Strings with Customers, would this line be correct?  No!  A String is
>> not a Customer, so you can't supply a String as the value; you need to
>> supply a Customer.
>> 
>> >       customer.put("456DEF",  "Janet Jones, address 145 Main Street,
>> >       area 1"); customer.put("789GHI",   "Christine Charter, address
>> >       50 Lake View, area 2");
>> >     }
>> >             
>> > }
>> > 
>> > the customer class has already been wrote
>> 
>>      Long years ago I had a student who approached his programming
>>      tasks
>> by throwing together a mish-mash of half-understood code-like source
>> lines, pondering the compiler's complaints, and making random change
>> after random change until he chanced upon something the compiler would
>> accept in silence.  This code would seldom then do what was intended,
>> so he'd keep on making herky-jerky changes until it eventually printed
>> what he thought might be the right answer for one test case, then he'd
>> hand the result in as his homework.
>> 
>>      I cannot recall that he ever submitted a program that would run a
>> second test case correctly.  And it's my strong impression that he did
>> not learn how to program.  He was the student and I the teacher, and
>> the fault for his lack of learning could lie with either side, but for
>> selfish reasons I decided the problem was his and not mine.  I put it
>> down to his tendency to scribble code before he'd really thought about
>> what he needed to do, in hopes that fixing his compile-time errors
>> would somehow guide him over the rough bits.
>> 
>>      The compiler is not a tutor.
>> 
>>      The compiler will not do your studying for you.
>> 
>>      The compiler will not teach you how to program.
>> 
>>      I strongly suggest that you start over again at Lesson One, and
>> resist the temptation to rush into writing code before gaining some
>> understanding.  It's likely that your experiences so far may help you
>> get more out of the material a second time around than you did on the
>> first attempt -- but I sincerely doubt you'll make meaningful progress
>> with the level of understanding you've demonstrated thus far.
>> 
>>      Study diligently, and good luck!
>> 
>> --
>> esosman@comcast-dot-net.invalid Thirteen hundred seventy-four days to
>> go.
> 
> I will take that on board Eric about your old Student and i understand
> that i shouldn't rush but to be fair i am 40 years of age now and i want
> to learn this is why i am looking for a tutor aswell

If you are essentially teaching yourself to write programs for your own 
pleasure and to understand the way to do it, you can do a lot worse than 
to get a copy of "The C Programming Language" edition 2 by Brian Kernighan 
and Denis Richie, download a C compiler and work your way through the 
book, writing, compiling and running the examples in each chapter. This 
is, quite simply, the best written book on learning to program that I 
know, and as a small (270 page) paperback its not a huge investment.

If you stick with C and, after that, read and work your way through "The 
Practice of Programming by Kernighan and Pike, you'll not only know how 
the program, but how to write readable, well-structured programs and how 
to make them easy to test as well. 

At that point you'll be equipped to learn and work with different 
programming languages and have the basis for using them fro solving 
almost any programming problem.

I know this is off-topic for this newsgroup, but if I knew any book that 
covered programming in Java as well as "K&R C ed. 2" covers C I'd have 
recommended that.
 

-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

[toc] | [prev] | [next] | [standalone]


#36482

FromArne Vajhøj <arne@vajhoej.dk>
Date2017-04-17 20:22 -0400
Message-ID<od3m8o$1j99$1@gioia.aioe.org>
In reply to#36481
On 4/17/2017 7:14 PM, Martin Gregorie wrote:
> If you are essentially teaching yourself to write programs for your own
> pleasure and to understand the way to do it, you can do a lot worse than
> to get a copy of "The C Programming Language" edition 2 by Brian Kernighan
> and Denis Richie, download a C compiler and work your way through the
> book, writing, compiling and running the examples in each chapter. This
> is, quite simply, the best written book on learning to program that I
> know, and as a small (270 page) paperback its not a huge investment.
>
> If you stick with C and, after that, read and work your way through "The
> Practice of Programming by Kernighan and Pike, you'll not only know how
> the program, but how to write readable, well-structured programs and how
> to make them easy to test as well.
>
> At that point you'll be equipped to learn and work with different
> programming languages and have the basis for using them fro solving
> almost any programming problem.
>
> I know this is off-topic for this newsgroup, but if I knew any book that
> covered programming in Java as well as "K&R C ed. 2" covers C I'd have
> recommended that.

If one was to learn a simpler procedural language before going
for a more complex object oriented language, then I would suggest
Pascal not C.

Arne

[toc] | [prev] | [next] | [standalone]


#36484

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2017-04-18 01:20 +0000
Message-ID<od3pkf$46n$1@dont-email.me>
In reply to#36482
On Mon, 17 Apr 2017 20:22:50 -0400, Arne Vajhøj wrote:

> On 4/17/2017 7:14 PM, Martin Gregorie wrote:
>> If you are essentially teaching yourself to write programs for your own
>> pleasure and to understand the way to do it, you can do a lot worse
>> than to get a copy of "The C Programming Language" edition 2 by Brian
>> Kernighan and Denis Richie, download a C compiler and work your way
>> through the book, writing, compiling and running the examples in each
>> chapter. This is, quite simply, the best written book on learning to
>> program that I know, and as a small (270 page) paperback its not a huge
>> investment.
>>
>> If you stick with C and, after that, read and work your way through
>> "The Practice of Programming by Kernighan and Pike, you'll not only
>> know how the program, but how to write readable, well-structured
>> programs and how to make them easy to test as well.
>>
>> At that point you'll be equipped to learn and work with different
>> programming languages and have the basis for using them fro solving
>> almost any programming problem.
>>
>> I know this is off-topic for this newsgroup, but if I knew any book
>> that covered programming in Java as well as "K&R C ed. 2" covers C I'd
>> have recommended that.
> 
> If one was to learn a simpler procedural language before going for a
> more complex object oriented language, then I would suggest Pascal not
> C.
> 
Fair enough, but can you recommend any readily obtainable Pascal book 
that's as good as either edition of the K&R C book? Some of the O'Reilly 
books come close but that's about it. 

As I said, if I knew of a Java book that could approach that standard, 
I'd have recommend it. I know some other excellent programming books, 
such as "A Very Informal Introduction to Algol68", the aforementioned 
"The Practise of Programming" and Sedgewick's "Algorithms", but none of 
these are suitable for a self-teaching beginner, let alone my other most-
referenced book apart from manpages, "UNIX Systems Programming for 
SVR4" (still relevant over 30 years later).

BTW, I don't much care what language somebody programs in: I alternate 
between C and Java with a bit of SQL and PHP on the side, but if they 
know an interesting new approach I haven't seen, bring it on!

HOWEVER, as Pablo has a looming test to pass and so turns out to be a 
student who (hasn't been paying attention|has a bad teacher|has some 
other problem|dogs ate his homework) anything I said isn't relevant.
 

-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.java.programmer


csiph-web