Results 1 to 1 of 1
- 11-15-2010, 03:06 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 1
- Rep Power
- 0
multiplying columns by row in 2d array
Hello
I've been banging my head against the wall with this.
Using the input from a GUI, I'm wanting to input rate and time values into a 2D array.
The number of rows is arbitrary (it does take into account a specified constraint -- the total number of minutes), but the columns hold rate and time values.
After entering in these rate and time values, a report is run which should total the rows by multiplying array[index][0] (rate) by array[index][1] time.
Averages are derived, and these figures are passed as a string to a textArea.
Here is the output in the textArea:
the first set of numbers are the created in the GUI with each action. "Report of your wages to date:" figures are from the reporting method.
Minutes: 60.0 Hourly Rate: 20.0 Earnings: 20.0
Minutes: 60.0 Hourly Rate: 30.0 Earnings: 30.0
Minutes: 60.0 Hourly Rate: 10.0 Earnings: 10.0
*****
Report of your wages to date:
Total minutes spent tutoring: 60.0
Total Earnings: 10.0
Average per hour rate: 0.16666666666666669
/
public class TutorLogic1 {
int rows = 12;
int columns = 2;
double[][] rateTime = new double[rows][columns];
public void getInputRate(double ratevalue1) {
int index2 = 0;
if (index2 <= rateTime.length - 1)
{
rateTime[index2][0] = ratevalue1;
index2++;
}
}
public void getInputTime(double timevalue1) {
int index1 = 0;
if (index1 <= rateTime.length - 1)
{
rateTime[index1][1] = timevalue1;
index1++;
}
}
//If total time is > 240, throw an exception
public double getTimeTotal() {
double totalTime = 0;
for (int index3 = 0; index3 < rateTime.length; index3++)
{
totalTime = totalTime + rateTime[index3][1];
}
return totalTime;
}
public String getReport() {
double timeTotal2 = 0;
double avgRate = 0;
double avgTime = 0;
double avgCalc = 0;
double rateSum = 0;
//the time value is divided by 60 to derive an hourly rate
for (int index4 = 0; index4 < rateTime.length; index4++)
{
rateSum = rateSum + rateTime[index4][0] * (rateTime[index4][1] / 60);
timeTotal2 = timeTotal2 + rateTime[index4][1];
}
avgRate = rateSum / rateTime.length;
avgTime = timeTotal2 / rateTime.length;
avgCalc = avgRate / avgTime;
String reportOutput = "\n" + "\n" + " *****" + "\n" +
"Report of your wages to date:\n" +
"Total minutes spent tutoring: " + timeTotal2 + "\n" +
"Total Earnings: " + rateSum + "\n" +
"Average per hour rate: " + avgCalc + "\n";
return reportOutput;
}
}
Any help would be greatly appreciated.
Thank you
Similar Threads
-
how to add columns from Matrices(2D array)
By John_shok in forum New To JavaReplies: 7Last Post: 10-04-2010, 04:33 PM -
Multiplying Values of an Array
By brmcdani in forum New To JavaReplies: 3Last Post: 02-06-2010, 04:00 AM -
Multiplying Variables
By rnavarro9 in forum New To JavaReplies: 4Last Post: 12-03-2009, 08:10 AM -
Counting the number of columns in a 2D array,
By KalEl in forum New To JavaReplies: 9Last Post: 10-21-2008, 05:27 AM -
Two diM aRRay and add rows and columns....
By filly444 in forum New To JavaReplies: 2Last Post: 08-30-2008, 05:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks