• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Counter Instance Variable

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I am about to flip. I already posted once with this code for this really bad defined assignment I was given and I need to figure out a way to count the number of arguments in my class I have created to decide where to put ? and & within a URL. My really vague professor says to use a counter instance variable that contains the number of arguments appended to the object's URL... I have no idea how to do this.

Here is the code that I have:


So how do I create a code to count the arguments that are appended to the URL to then figure out where to put ? and & in the URL?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I already posted once with this code for this really bad defined assignment I was given and I need to figure out a way to count the number of arguments in my class I have created to decide where to put ? and & within a URL. My really vague professor says to use a counter instance variable that contains the number of arguments appended to the object's URL...



To be blunt, you are being "really vague" too.

What is the definition of "number of aurgments in [your] class"? Since when does a class have arguments? We have no idea what this is, much less know what it means to count it.

What does "put ? and & within a URL" have to do with a Java class? What the heck is an "object's URL"?

Henry
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and I have already made a suggestion, taking the trouble to run your app myself. So don't post the same thing twice.
 
Ryan Speller
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I am such a beginner with Java so its really hard for me to know whats like well known as of terms or what my professor is just using in our class, that from what I can tell no one else has really done.

Heres the runtime output I get from running the program:


Enter URL site (or 'exit')...
www.amazon.com
Url value read was: www.amazon.com
Enter URL argument name (or 'done')...
id
Enter type of argument value (string, integer, double)...
integer
Enter an integer value
123
Enter URL argument name (or 'done')...
name
Enter type of argument value (string, integer, double)...
string
Enter a string value
john connor
Enter URL argument name (or 'done')...
book
Enter type of argument value (string, integer, double)...
integer
Enter an integer value
666222
Enter URL argument name (or 'done')...
done
URL with appended arguments is:
http://www.amazon.comid=123name=john+connorbook=666222

Enter URL site (or 'exit')...



Basically with the URL it is coming out like this:
http://www.amazon.comid=123name=john+connorbook=666222
When I need it to look like this:
http://www.amazon.com?id=123&name=john+connor&book=666222

and of course this all depends on how the URL is entered into the program.

I posted the class I have up above and that is running within the source code that my professor gave me here:



So what I am trying to figure out is a way to put the ? after the .com, like www.amazon.com?id=123, and then put the & after each proceeding argument, like www.amazon.com?id=123&name=john+connor&book=666222 having the & marks end at the last argument so I dont end up with something like, www.amazon.com?id=123&name=john+connor&book=666222&.

Also I cant just put a ? after the URL, because incase I enter just www.amazon.com without any arguments, it doesnt come out looking like www.amazon.com?, but comes out looking like just normal www.amazon.com.

So I need some sort of code (I am so lost on what are the right words to use to describe what I need) to check where each name=value (ex. id=123) comes after the original URL to decide where to put the ? and & in the URL.

Sorry for the vagueness before, but as you can tell I am very frustrated with this and the professor for this class is not very helpful at all.

THANK YOU SO MUCH!!!
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So I need some sort of code (I am so lost on what are the right words to use to describe what I need) to check where each name=value (ex. id=123) comes after the original URL to decide where to put the ? and & in the URL.

Sorry for the vagueness before, but as you can tell I am very frustrated with this and the professor for this class is not very helpful at all.



Hate to break the news to you, but I think your professor is not being vague at all -- he pretty much came really close to giving you the answer !!

I think you are coming at the problem the wrong way. You want to fix the broken URL by inserting the "?" and "&" in to the URL. In fact, you should just fix the addArgument() method... when the URL is being generated in the first place.

The addArgument() method should keep track of the times that it is being called (ie. the number of arguments). The first time, it will need to append the "?" first, and sequential times, it will need to append the "&" first. This is also why your profession suggested using an instance variable, as using local variables won't keep state between calls.

Henry
 
Ryan Speller
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
eh... Yeah I figured it was something like that. To put it easy, I am awful at programming, this is a required course and I have just had wayyyyy too tough of a time with it.
I really hate to be asking so much because you have now clarified a better portion of it.
But could you possibly show me what it would actually look like?
You can just give me an example not with my code if this has some sort of moral impact on how you go about helping people.

THANK YOU SO MUCH THOUGH!
 
Ryan Speller
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anyone give me a hand? Basically this assignment was a due awhile ago, and I am just terrible at java programming and seriously dont know how to use an instance variable to count the number of addArguments in my class to decide where to put ? and &. I would really appreciate any type of example someone could give me of what this needs to look like.

Thank you again
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You already have an example. In the code you originally posted, the variable "mUrl" is an instance variable. Notice that it isn't inside a method or a constructor; if it were, then it would be a local variable.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not only that, to add a counter and an if condition to the addArgument() method, to add the punctuations, is what? ... 2 lines... 3 lines at most. It is certainly much much easier than what you have done so far.

You keep saying you are "terrible at java programming" -- and don't seem to want to attempt it without help.... but quite frankly, this change is nothing compared to what you have done so far. What is it about this last one percent of your homework assignment that is different from the previous 99%, that you don't feel comfortable that you can do it?

Give it a try. I have pretty much explained everything in english "pseudo code".

Henry
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic