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


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

Please help

Started byrustboy86@gmail.com (rustboy86)
First post2017-12-07 06:02 +1200
Last post2017-12-07 21:48 +1200
Articles 17 — 3 participants

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


Contents

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

#37753 — Please help

Fromrustboy86@gmail.com (rustboy86)
Date2017-12-07 06:02 +1200
SubjectPlease help
Message-ID<835507970@f38.n261.z1.binkp.net>
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]


#37754

FromEric Douglas <e.d.programmer@gmail.com> (Eric Douglas)
Date2017-12-07 07:10 +1200
Message-ID<3191932149@f38.n261.z1.binkp.net>
In reply to#37753
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]


#37755

Fromrustboy86@gmail.com (rustboy86)
Date2017-12-07 07:33 +1200
Message-ID<1991418620@f38.n261.z1.binkp.net>
In reply to#37754
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]


#37756

FromEric Douglas <e.d.programmer@gmail.com> (Eric Douglas)
Date2017-12-07 08:22 +1200
Message-ID<3572599534@f38.n261.z1.binkp.net>
In reply to#37755
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]


#37757

Fromrustboy86@gmail.com (rustboy86)
Date2017-12-07 08:31 +1200
Message-ID<3138149533@f38.n261.z1.binkp.net>
In reply to#37756
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]


#37759

FromEric Douglas <e.d.programmer@gmail.com> (Eric Douglas)
Date2017-12-07 08:54 +1200
Message-ID<2409366975@f38.n261.z1.binkp.net>
In reply to#37757
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]


#37760

Fromrustboy86@gmail.com (rustboy86)
Date2017-12-07 09:29 +1200
Message-ID<2220899802@f38.n261.z1.binkp.net>
In reply to#37759
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]


#37762

FromEric Douglas <e.d.programmer@gmail.com> (Eric Douglas)
Date2017-12-07 10:11 +1200
Message-ID<3928596342@f38.n261.z1.binkp.net>
In reply to#37760
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]


#37761

FromKiwi User <martin@mydomain.invalid> (Kiwi User)
Date2017-12-07 18:04 +1200
Message-ID<3328178663@f38.n261.z1.binkp.net>
In reply to#37759
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]


#37763

FromEric Douglas <e.d.programmer@gmail.com> (Eric Douglas)
Date2017-12-07 10:14 +1200
Message-ID<2264931732@f38.n261.z1.binkp.net>
In reply to#37761
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]


#37764

Fromrustboy86@gmail.com (rustboy86)
Date2017-12-07 10:36 +1200
Message-ID<3464228628@f38.n261.z1.binkp.net>
In reply to#37763
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]


#37765

FromEric Douglas <e.d.programmer@gmail.com> (Eric Douglas)
Date2017-12-07 10:44 +1200
Message-ID<1087264470@f38.n261.z1.binkp.net>
In reply to#37764
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]


#37766

Fromrustboy86@gmail.com (rustboy86)
Date2017-12-07 11:04 +1200
Message-ID<4106325146@f38.n261.z1.binkp.net>
In reply to#37765
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]


#37769

FromEric Douglas <e.d.programmer@gmail.com> (Eric Douglas)
Date2017-12-07 13:35 +1200
Message-ID<3819122495@f38.n261.z1.binkp.net>
In reply to#37766
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]


#37767

FromKiwi User <martin@mydomain.invalid> (Kiwi User)
Date2017-12-07 21:22 +1200
Message-ID<579199865@f38.n261.z1.binkp.net>
In reply to#37763
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]


#37768

FromEric Douglas <e.d.programmer@gmail.com> (Eric Douglas)
Date2017-12-07 13:32 +1200
Message-ID<1905396492@f38.n261.z1.binkp.net>
In reply to#37767
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]


#37770

FromKiwi User <martin@mydomain.invalid> (Kiwi User)
Date2017-12-07 21:48 +1200
Message-ID<2134599174@f38.n261.z1.binkp.net>
In reply to#37768
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