Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Lexi Turgeon

Ranch Hand
+ Follow
since Oct 27, 2016
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lexi Turgeon

Help me in my statistics class! Click this link to take a survey. It is only two questions and will take at most 2 minutes! Thank you in advance!

Link to survey: https://docs.google.com/forms/d/e/1FAIpQLSdYv05cj_ubObdRg2wLrO5m-cqBncj2ghj3eNUQy5pt39ETCQ/viewform?usp=sf_link
3 years ago
Did not forget, just do not know how to. Any tips on that?
3 years ago
I have this code:

and my theOutput(); method in my main says Non-Static method cannot be referenced from a static context. Is there any way to get around this or fix this error?
3 years ago

Campbell Ritchie wrote:You doubtless mean four of the following six. And I can count, because nobody is going to use applets, so that makes six.



If you choose to look at it that way, then yes!
3 years ago
Hello,
I have to make a final project for my Java class but I am not sure what I should do. I am allowed to do anything I want as long as it includes at least 4 of the following:
-Arrays
-Sorting
-Recursion
-Swing
-File I/O
-Using several methods of the Java "String" class, such as substr, charAt, length (see Chapter 7 for examples)
-Create your own java class (defining an object)
-Create your program as an applet

Does anyone have any ideas as to what I could do?
3 years ago

Carey Brown wrote:You already have an order, you named it "computer", what you don't have is "extras". You if() statements bail out as soon as one is true so your requirement "any of the buttons selected" is not being met. You shouldn't return until the end of the method.



How would I make it so every button will add that value to computer? I can't simple remove the return.
3 years ago
So I have these two methods that are for a Java Swing project. The first method is supposed to calculate the cost of a computer plus any of the buttons selected in the GUI. My problem is how do I create the variable so that I can add each button to total up on the order?
3 years ago

Junilu Lacar wrote:
I assume you meant "call from main()" -- my question would be, was this code provided to you like this? If so, then you'd need an instance of the class that this method is found in. Otherwise, you'd make it a static method as already discussed.



If I make that method static, and call it from main like this:
I get a compiler error:


How would I make the variables static?
3 years ago

Junilu Lacar wrote:The question I would ask is why is the class named "Cards" (plural) when an object of this type represents only ONE card?


Because there are other methods in the program that do things with multiple cards.
3 years ago
Couldn't I just change the "parseCard" method to static?
3 years ago

Sankalp Bhagat wrote:
And to call that method from main method, you have to create an object of the class where you have written that method as the method is non-static method and you are calling it from the static context as main method is static. And then call that method from that object reference and as your method is returning Cards object you have to assign the result the Cards.
such as



Could you rephrase this? I am a bit confused on it. I somewhat understand it but I need to reread it worded differently.
3 years ago
I am given this method called parseCard and it takes a String and returns the corresponding card.
This is the method:


My question is how do I call this method to main?
3 years ago
Never mind I found my problem and figured out how to use it with an idea from Campbell Ritchie.
3 years ago

Junilu Lacar wrote:As far as testing your code is concerned, I don't see anything in the requirement statement that you posted that prevents you from following Campbell's suggestion.


Oh I see what you mean, but When I put that code in my main, what is supposed to replace the portion of it? Is that where my class name goes?
3 years ago
I am not sure how to make this that I was given to take an array of 10 random integers.
3 years ago