Kris French

Greenhorn
+ Follow
since Aug 28, 2014
Merit badge: grant badges
For More
Japan
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kris French

Thank you all for your help. I knew nothing was getting stored in the array, but I just needed to figure out why. After some digging, it looked like using the Scanner was the way to go. I imported the Scanner utility and added the appropriate line of code to the program, but then I kept getting array.index.outofbounds exception. I did some reading on why this happens and it turned out that in the first loop, I was using and when I switched to the program worked as it was intended.

Now my next challenge is to get the Number to count. for example; "Enter 10 numbers" then the program will print Number 1, Number 2, etc. Anyway, here is the program. Again thank you:



Kris
9 years ago
Oops...thank you Joanne. There were a few changes made when I was researching how to accomplish this. I do have to use the Array.sort() method.

Here is where I was when I thought I was on the right track:

9 years ago
Hello Everybody,

I'm trying to sort 10 inputted numbers (double precision) using the Array.sort() method. I'm actually kind of proud that I made it this far on my own, but I have ran into a wall.

I can get the 10 numbers inputted, but the output is ten 0.0s; now (and this how I know I am learning some things) I'm fairly certain that the variable number is not storing the numbers inputted by the user otherwise I wild be seeing the program work correctly.

So my question is why isn't number storing the inputs?





As always, thank you for the help.

Kris
9 years ago
I came back to this today. I went line by line in the code, went through all the posts and spent some time reading through javadoc on the oracle site. For the second time Campbell's subtle nudge in the right direction caused me to smack my forehead. I had most everything just about there, but when I relaxed, looked at the code logically and did a little research (guided by all of you) the solution was so simplistic I feel embarrassed for being thick-headed. Thank you all for being understanding, and most of all, making me do it on my own! Here is the final result:


9 years ago
Thank you Rico; that's exactly what I needed.

Kris
9 years ago
Hello Mike,

What do you mean by

you're entering values using a JOptionPane but reading from stdin.

?
9 years ago
There is nothing worse than trying to focus when you've had some bad beer and bad Chinese food on a Friday.
9 years ago
No Dave this was this first for me, but I'll try to search; maybe I'll learn something Thank you for the help!

Kris
9 years ago
J,

You are right; I changed the count variable to 1 and all it did was add 1 + count. I never noticed before because the program terminated after inputting only one number. I probably would have encountered that if it worked the way I thought it would, but may have gotten a bit stuck then. Should I get rid of the = 0; and try to initialize count some other way? Thanks for the catch; I tend to get a bit of tunnel vision when I think I know exactly what the problem is.

Kris
9 years ago
Hello once again!

I hope I'm not making a pest of myself, but I do like the way your answers/questions help me figure things out on my own and help me better understand Java. I do have a class project that has some restrictions. I have read and understand the details, and even have a plan to build the program (I'm taking Campbell's advice and building it in small pieces first, then adding to the whole.) The project description is:


This project focuses on the use of of sequential, selective and repetitive programming statements, methods, and modular programming.
1. Design and implement a Java program that will gather a group of floating point numbers and determine the sum and average of the data entered. The program should use separate methods for inputting the data, calculating the sum, calculating the average, and displaying the results. A sentinel value should be used to indicate the user has completed entering their numbers. The output should display a message that includes the count of the numbers entered, the sum of the numbers and the average of the numbers. If the sum of the numbers is greater than 100, a warning message should be displayed indicating “values have exceeded a sum 100”.

2. Additional requirements include:

1. Use JOptionPane.showInputDialog() methods for your user to input their data

2. Use JOptionPane.showMessageDialog() methods to display your messages.

I have started by asking the user to input a number using the JOptionPane.showInputDialog; checks good.
Now I am working on getting the program to count the amount of numbers entered. I felt this was a logical next step. After much trial and error, I finally got the program to output the number of times numbers were entered. The problem I am running into is that it seems that the program terminates after only one input is made. It seems like the program is skipping the while statement entirely. Below is the code:



Thank you in advance for the help! I can't wait until I'm proficient enough to pay it forward!

Kris
9 years ago
Thank you all for helping me understand; I'm almost there. Unfortunately I have a class project due and I have spent a littler too long trying to figure out this problem, so I have to set this aside for now. I am going to finish this program, but probably not until next week when I have more time. I don't want you to feel that I have wasted your time; I WILL finish this. I value your experience and will most definitely have more questions in the very near future and do not want to burn these helpful bridges ;).

Thanks again!

Kris

9 years ago

This sounds odd - there is no if statement in the main method (which is what you should have been altering - the dogYearCalc method was OK).

The javadocs of the JOptionPane class show how to get the user input from showInputDialog. It's a String object, which you'll have to convert to a double - the java.lang.Double class has methods that can do that.



I have seen examples of this while trying to figure this out, but have no idea how, or when, to use the java.lang.Double class. would it be something like:



9 years ago
Ulf,

I was glad to see you responded; that's exactly what I did. Now I'm trying to figure out how to take the user input without the "double humanAge = 30.0;" actually getting added into the if statement. Is there some sort of generic way to declare without messing up the math? Thank you!

Kris
9 years ago
Ulf,

I thought I was calling humanAge to the main from the dogYearCalc method. I take it from your question that is wrong. I really do not know what exactly to put in the parenthesis. I was thinking that the variable humanAge would have been appropriate.

Kris
9 years ago
Thank you all for the push in the right direction. I am still working out the kinks. There a few things that I just don't understand that I am trying to understand. For example, I know that the main method is supposed to call from the dogYearCalc method and that method is doing all of the calculations and sending them to the main. I guess it is the finer details of getting those calculations to the main is where I am running into a wall. For those of you who helped and is still curious, here is where I stand now:



Thank you again!

Kris
9 years ago