Results 1 to 3 of 3
- 02-23-2013, 08:05 PM #1
Member
- Join Date
- Feb 2013
- Location
- Baltimore, MD
- Posts
- 10
- Rep Power
- 0
How do I print a string and array value in the same line of text?
Hello All,
I'm working on a program that tracks tutoring earnings. The program uses a GUI where the user enters time and earnings for each tutoring session. The program stores the input values in a 2D array when an enter button is pushed, calculates the total time spent tutoring, avg earnings, total earnings, minimum wage earned and whether the earnings are avg, above or below. These calculations are displayed in a specific format in the GUI text box when a report button is pushed.
Right now, I am having difficulty determining how to display a string alongside the array value. Based on the required output, each time the enter button is pushed, the time and earnings should be displayed. This is my code for the enter button method thus far:
This is the required output:Java Code:private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) { double time = Double.parseDouble(sessionLength.getText()); double earnings = Double.parseDouble(earningsReceived.getText()); //each time user enters the time spent and earnings received for each //tutor session, those values will be added to the array. //positive input warning if (time <= 0 || earnings <= 0) { Component frame = null; JOptionPane.showMessageDialog(frame,"Values for time and earnings must be positive numbers", "Invalid Input Warning", JOptionPane.WARNING_MESSAGE); return; } else { tutorArray[i][0] = time; tutorArray[i][1] = earnings; //determine the minimum wage if (earnings < tutorArray [i][1]) { minimumWage = earnings; } else { minimumWage = tutorArray [i][1]; } totalMinutes += time; totalWages += earnings; //clear text area output dataTextArea.setText(" "); //display time and earnings so far dataTextArea.append("Minutes =" + " " + "Earnings =\n"); i++; }
Minutes = 60.0 Earnings = $10.0
Minutes = 120.0 Earnings = $40.0
This is my last output:

Any assistance will be greatly appreciated and YES, I AM Java-challenged! Thanks for noticing!
Scott
- 02-23-2013, 08:34 PM #2
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
Re: How do I print a string and array value in the same line of text?
First thing I notice:
If you set them equal, how can this if statement ever be true?Java Code:tutorArray[i][1] = earnings; if (earnings < tutorArray [i][1]) { ... }
Second,
just concatenate the values to the string like this:
Java Code:dataTextArea.append("Minutes = " + totalMinutes + " " + "Earnings = " + totalWages + "\n");
- 02-24-2013, 12:11 AM #3
Member
- Join Date
- Feb 2013
- Location
- Baltimore, MD
- Posts
- 10
- Rep Power
- 0
Re: How do I print a string and array value in the same line of text?
Thanks for the reply and the insight, Andrew! How could I forget the rules of concatenation????
I understand your logic as far as my "if" statement. This was my attempt to assign the minimum wage, which will be necessary for the reporting method that follows this. I'm not sure how else to code that functionality.
Similar Threads
-
Skipe line if text in array?
By fpena06 in forum New To JavaReplies: 7Last Post: 04-27-2012, 12:13 PM -
Help with Printing Array... Im supposed to print out so 9 elements show per line.
By s_mxyzptlk in forum New To JavaReplies: 3Last Post: 03-08-2012, 01:09 AM -
how to print the String Array?
By nirasiva in forum New To JavaReplies: 4Last Post: 06-09-2011, 03:07 PM -
Text file into an array then Print
By Mrussell9 in forum New To JavaReplies: 0Last Post: 05-06-2011, 01:28 PM -
Print String from an Array
By adityasirohi in forum New To JavaReplies: 2Last Post: 02-18-2010, 04:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks