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


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

Please help

Started byrustboy86@gmail.com
First post2017-12-07 06:02 -0800
Last post2017-12-07 21:48 +0000
Articles 17 — 3 participants

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


Contents

  Please help rustboy86@gmail.com - 2017-12-07 06:02 -0800
    Re: Please help Eric Douglas <e.d.programmer@gmail.com> - 2017-12-07 07:10 -0800
      Re: Please help rustboy86@gmail.com - 2017-12-07 07:33 -0800
        Re: Please help Eric Douglas <e.d.programmer@gmail.com> - 2017-12-07 08:22 -0800
          Re: Please help rustboy86@gmail.com - 2017-12-07 08:31 -0800
            Re: Please help Eric Douglas <e.d.programmer@gmail.com> - 2017-12-07 08:54 -0800
              Re: Please help rustboy86@gmail.com - 2017-12-07 09:29 -0800
                Re: Please help Eric Douglas <e.d.programmer@gmail.com> - 2017-12-07 10:11 -0800
              Re: Please help Kiwi User <martin@mydomain.invalid> - 2017-12-07 18:04 +0000
                Re: Please help Eric Douglas <e.d.programmer@gmail.com> - 2017-12-07 10:14 -0800
                  Re: Please help rustboy86@gmail.com - 2017-12-07 10:36 -0800
                    Re: Please help Eric Douglas <e.d.programmer@gmail.com> - 2017-12-07 10:44 -0800
                      Re: Please help rustboy86@gmail.com - 2017-12-07 11:04 -0800
                        Re: Please help Eric Douglas <e.d.programmer@gmail.com> - 2017-12-07 13:35 -0800
                  Re: Please help Kiwi User <martin@mydomain.invalid> - 2017-12-07 21:22 +0000
                    Re: Please help Eric Douglas <e.d.programmer@gmail.com> - 2017-12-07 13:32 -0800
                      Re: Please help Kiwi User <martin@mydomain.invalid> - 2017-12-07 21:48 +0000

#37718 — Please help

Fromrustboy86@gmail.com
Date2017-12-07 06:02 -0800
SubjectPlease help
Message-ID<4edadd79-efc8-476a-8d38-36887755b1fa@googlegroups.com>
I`m doing a Uni course using BlueJ and i`m really stuck i have to....

In the class M250Account: 
(i) Declare a private instance variable of type String called accountNum. 

(ii) Edit the constructor for M250Account so that it initialises the accountNum instance variable to the account number "X00000". 

(iii) Write a getter method for the accountNum instance variable. 

but i don`t know how to start. i`ve already created a new class M250Account 

[toc] | [next] | [standalone]


#37719

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-12-07 07:10 -0800
Message-ID<7d136305-b0dd-4ade-98d4-89db7106955d@googlegroups.com>
In reply to#37718
On Thursday, December 7, 2017 at 9:02:27 AM UTC-5, rust...@gmail.com wrote:
> I`m doing a Uni course using BlueJ and i`m really stuck i have to....
> 
> In the class M250Account: 
> (i) Declare a private instance variable of type String called accountNum. 
> 
> (ii) Edit the constructor for M250Account so that it initialises the accountNum instance variable to the account number "X00000". 
> 
> (iii) Write a getter method for the accountNum instance variable. 
> 
> but i don`t know how to start. i`ve already created a new class M250Account

That sounds about as basic as it gets.  Have you tried the tutorial?
https://docs.oracle.com/javase/tutorial/

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


#37720

Fromrustboy86@gmail.com
Date2017-12-07 07:33 -0800
Message-ID<d786c841-f747-4848-971d-4c222ef5d834@googlegroups.com>
In reply to#37719
On Thursday, December 7, 2017 at 3:11:08 PM UTC, Eric Douglas wrote:
> On Thursday, December 7, 2017 at 9:02:27 AM UTC-5, rust...@gmail.com wrote:
> > I`m doing a Uni course using BlueJ and i`m really stuck i have to....
> > 
> > In the class M250Account: 
> > (i) Declare a private instance variable of type String called accountNum. 
> > 
> > (ii) Edit the constructor for M250Account so that it initialises the accountNum instance variable to the account number "X00000". 
> > 
> > (iii) Write a getter method for the accountNum instance variable. 
> > 
> > but i don`t know how to start. i`ve already created a new class M250Account
> 
> That sounds about as basic as it gets.  Have you tried the tutorial?
> https://docs.oracle.com/javase/tutorial/

ive tried everything i just cant do it

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


#37721

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-12-07 08:22 -0800
Message-ID<93e9bca8-c0e8-4a12-bb30-9f5548f611c3@googlegroups.com>
In reply to#37720
On Thursday, December 7, 2017 at 10:33:37 AM UTC-5, rust...@gmail.com wrote:
> 
> ive tried everything i just cant do it

The tutorial should spell out exactly how to do that.  What part gets you stuck?  Have you written any code yet?  What does that look like?

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


#37722

Fromrustboy86@gmail.com
Date2017-12-07 08:31 -0800
Message-ID<200bfada-8168-4bf1-88de-8cb9016aec1a@googlegroups.com>
In reply to#37721
On Thursday, December 7, 2017 at 4:23:31 PM UTC, Eric Douglas wrote:
> On Thursday, December 7, 2017 at 10:33:37 AM UTC-5, rust...@gmail.com wrote:
> > 
> > ive tried everything i just cant do it
> 
> The tutorial should spell out exactly how to do that.  What part gets you stuck?  Have you written any code yet?  What does that look like?

So far i have written....(Which is wrong)

public class M250Account
{
   /* instance variables */
   
   private String accountNum; 
   private int X00000;
   private double balance;
 
    /**
    * Constructor for objects of class M250Account
    */
   public M250Account()
   {
     this.accountNum = X00000;
   }

   /**
    * An example of a method - replace this comment with your own
    */
   public getAccountNum() 
   {
      return this.accountNum;
   }
}

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


#37724

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-12-07 08:54 -0800
Message-ID<367d1efe-674a-4e85-9887-816ebd57affe@googlegroups.com>
In reply to#37722
On Thursday, December 7, 2017 at 11:31:40 AM UTC-5, rust...@gmail.com wrote:
> So far i have written....(Which is wrong)
> 
> public class M250Account
> {
>    /* instance variables */
>    
>    private String accountNum; 
>    private int X00000;
>    private double balance;
>  
>     /**
>     * Constructor for objects of class M250Account
>     */
>    public M250Account()
>    {
>      this.accountNum = X00000;
>    }
> 
>    /**
>     * An example of a method - replace this comment with your own
>     */
>    public getAccountNum() 
>    {
>       return this.accountNum;
>    }
> }

Did you compile this with your BlueJ to see your error?
All I'm seeing wrong with this is your getter method forgetting to declare the return type.

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


#37725

Fromrustboy86@gmail.com
Date2017-12-07 09:29 -0800
Message-ID<4e9ebac0-22e9-461b-bc51-2ab4d10a4810@googlegroups.com>
In reply to#37724
On Thursday, December 7, 2017 at 4:54:27 PM UTC, Eric Douglas wrote:
> On Thursday, December 7, 2017 at 11:31:40 AM UTC-5, rust...@gmail.com wrote:
> > So far i have written....(Which is wrong)
> > 
> > public class M250Account
> > {
> >    /* instance variables */
> >    
> >    private String accountNum; 
> >    private int X00000;
> >    private double balance;
> >  
> >     /**
> >     * Constructor for objects of class M250Account
> >     */
> >    public M250Account()
> >    {
> >      this.accountNum = X00000;
> >    }
> > 
> >    /**
> >     * An example of a method - replace this comment with your own
> >     */
> >    public getAccountNum() 
> >    {
> >       return this.accountNum;
> >    }
> > }
> 
> Did you compile this with your BlueJ to see your error?
> All I'm seeing wrong with this is your getter method forgetting to declare the return type.

the error is on 

public getAccountNum() 

invalid method declaration; return type required

What should i put? 

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


#37727

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-12-07 10:11 -0800
Message-ID<e5327dc2-2f4c-4aa8-98b7-f03fefc61db9@googlegroups.com>
In reply to#37725
On Thursday, December 7, 2017 at 12:30:02 PM UTC-5, rust...@gmail.com wrote:
> 
> the error is on 
> 
> public getAccountNum() 
> 
> invalid method declaration; return type required
> 
> What should i put?

This is a basic you would learn in the free tutorial if you follow from the beginning you'd get to it in this section..
https://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html

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


#37726

FromKiwi User <martin@mydomain.invalid>
Date2017-12-07 18:04 +0000
Message-ID<p0bvri$mki$2@news.albasani.net>
In reply to#37724
On Thu, 07 Dec 2017 08:54:05 -0800, Eric Douglas wrote:

> Did you compile this with your BlueJ to see your error?
> All I'm seeing wrong with this is your getter method forgetting to
> declare the return type.
>
There's an error in the constructor too: no double quotes round the 
String constant.


-- 
Martin    | martin at
Gregorie  | gregorie
          | dot org

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


#37728

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-12-07 10:14 -0800
Message-ID<4cd638e1-3341-411e-a1f5-d27b121ca363@googlegroups.com>
In reply to#37726
On Thursday, December 7, 2017 at 1:04:56 PM UTC-5, Kiwi User wrote:
> > Did you compile this with your BlueJ to see your error?
> > All I'm seeing wrong with this is your getter method forgetting to
> > declare the return type.
> >
> There's an error in the constructor too: no double quotes round the 
> String constant.
> 
> 

That is actually a runtime error.  It does look like the instructions say to initialize it to the string constant "X00000" while this code is initializing the String variable to the String value of the int variable X00000 which is not assigned.

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


#37729

Fromrustboy86@gmail.com
Date2017-12-07 10:36 -0800
Message-ID<b37a4e96-1e88-44f9-aa22-6cba30a9eb3b@googlegroups.com>
In reply to#37728
On Thursday, December 7, 2017 at 6:14:29 PM UTC, Eric Douglas wrote:
> On Thursday, December 7, 2017 at 1:04:56 PM UTC-5, Kiwi User wrote:
> > > Did you compile this with your BlueJ to see your error?
> > > All I'm seeing wrong with this is your getter method forgetting to
> > > declare the return type.
> > >
> > There's an error in the constructor too: no double quotes round the 
> > String constant.
> > 
> > 
> 
> That is actually a runtime error.  It does look like the instructions say to initialize it to the string constant "X00000" while this code is initializing the String variable to the String value of the int variable X00000 which is not assigned.

I just dont get it at all ive tried re-writing but nothing works 

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


#37730

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-12-07 10:44 -0800
Message-ID<2a210675-0b54-4bf5-8fe6-a241915adaa1@googlegroups.com>
In reply to#37729
On Thursday, December 7, 2017 at 1:36:37 PM UTC-5, rust...@gmail.com wrote:
> > That is actually a runtime error.  It does look like the instructions say to initialize it to the string constant "X00000" while this code is initializing the String variable to the String value of the int variable X00000 which is not assigned.
> 
> I just dont get it at all ive tried re-writing but nothing works

I think it's spelled out pretty clearly.  What part don't you "get"?  The concept of declaring a return type, or the difference between a variable name and a String constant?

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


#37731

Fromrustboy86@gmail.com
Date2017-12-07 11:04 -0800
Message-ID<1f724cab-0a5c-4fe4-86eb-bd9b95af5034@googlegroups.com>
In reply to#37730
On Thursday, December 7, 2017 at 6:44:31 PM UTC, Eric Douglas wrote:
> On Thursday, December 7, 2017 at 1:36:37 PM UTC-5, rust...@gmail.com wrote:
> > > That is actually a runtime error.  It does look like the instructions say to initialize it to the string constant "X00000" while this code is initializing the String variable to the String value of the int variable X00000 which is not assigned.
> > 
> > I just dont get it at all ive tried re-writing but nothing works
> 
> I think it's spelled out pretty clearly.  What part don't you "get"?  The concept of declaring a return type, or the difference between a variable name and a String constant?

i dont understand what parts ive done wrong and how to correct it.

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


#37734

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-12-07 13:35 -0800
Message-ID<f5e8e7d9-0976-4074-9d6e-56d03abc5d76@googlegroups.com>
In reply to#37731
On Thursday, December 7, 2017 at 2:04:37 PM UTC-5, rust...@gmail.com wrote:
> 
> i dont understand what parts ive done wrong and how to correct it.

No one wants to do your homework for you.  You can't learn by copy and paste if you can't read what you've just pasted well enough to write something similar on your own.  I pointed you to the resource that should have the answer staring you in the face.  If you still don't understand you should ask the teacher.

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


#37732

FromKiwi User <martin@mydomain.invalid>
Date2017-12-07 21:22 +0000
Message-ID<p0cbf2$guu$1@news.albasani.net>
In reply to#37728
On Thu, 07 Dec 2017 10:14:09 -0800, Eric Douglas wrote:

> On Thursday, December 7, 2017 at 1:04:56 PM UTC-5, Kiwi User wrote:
>> > Did you compile this with your BlueJ to see your error?
>> > All I'm seeing wrong with this is your getter method forgetting to
>> > declare the return type.
>> >
>> There's an error in the constructor too: no double quotes round the
>> String constant.
>> 
>> 
>> 
> That is actually a runtime error.  It does look like the instructions
> say to initialize it to the string constant "X00000" while this code is
> initializing the String variable to the String value of the int variable
> X00000 which is not assigned.

Nope. Line 11 gives a compile-time error (javac 1.8.0_91). 
Try it yourself.


-- 
Martin    | martin at
Gregorie  | gregorie
          | dot org

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


#37733

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-12-07 13:32 -0800
Message-ID<e4b3fa88-4f24-444c-9673-61a759d9ff85@googlegroups.com>
In reply to#37732
On Thursday, December 7, 2017 at 4:23:03 PM UTC-5, Kiwi User wrote:
> 
> Nope. Line 11 gives a compile-time error (javac 1.8.0_91). 
> Try it yourself.
> 

So it does.  I was thinking that's one of the automatic conversions.
Apparently String and int are only automatically compatible if you were to do something like this.

this.accountNum = X00000 + "";

(though the correct answer to this homework question is still:)
this.accountNum = "X00000";

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


#37735

FromKiwi User <martin@mydomain.invalid>
Date2017-12-07 21:48 +0000
Message-ID<p0ccv1$eht$1@news.albasani.net>
In reply to#37733
On Thu, 07 Dec 2017 13:32:49 -0800, Eric Douglas wrote:

> So it does.  I was thinking that's one of the automatic conversions.
> Apparently String and int are only automatically compatible if you were
> to do something like this.
> 
> this.accountNum = X00000 + "";
>
Yep. I do that often enough when building diagnostic println() 
parameters, though almost never in assignment statements. 
Generally I prefer the neatness of String.format()
 
> (though the correct answer to this homework question is still:)
> this.accountNum = "X00000";
>
Yes, total agreement here. Beginners learning to rely on automatic 
conversion is likely to bite them sooner rather than later.


-- 
Martin    | martin at
Gregorie  | gregorie
          | dot org

[toc] | [prev] | [standalone]


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


csiph-web