Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Need help with arrays in Java
New Posts  All Forums:Forum Nav:

Need help with arrays in Java - Page 2

post #11 of 23
Basically put: Yes, their is a far better and easier way to do the code the assignment you completed. I would very much recommend re working the problem with the provided outline above but make sure you understand what is going on! If you are going for a computer science degree or computer engineering degree learning how to quickly do these problems in a good way will put you ahead of your peers quickly.
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
post #12 of 23
Thread Starter 
Quote:
Originally Posted by Fullinator View Post

Basically put: Yes, their is a far better and easier way to do the code the assignment you completed. I would very much recommend re working the problem with the provided outline above but make sure you understand what is going on! If you are going for a computer science degree or computer engineering degree learning how to quickly do these problems in a good way will put you ahead of your peers quickly.
Okay, but just to be clear...for loops are best for dealing with arrays, and I shouldn't really need while loops for arrays? This is probably a dumb question, but right now I'm not a great programmer. I'm taking this class to see if I wana do programming. My teacher is actually very hardcore grader too sadsmiley.gif
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
post #13 of 23
For loops are better in situations where you know you have to loop n number of times. In java you can find the length of the array and so you can loop through the entire array using a for loop! Remember that arrays start at index zero!

While loops are better if you are looping until a condition is met or not met. For example: I want the user to input the number 45. I will loop until the input is equal to 45.

There is also a thing called a do while loop. This is basically a while loop but is guaranteed to loop at least once.

Another cool piece of info you might want to know are the continue and break directives. continue will basically skip the rest of the code in the loop and go to the next loop iteration. Break will just stop looping all together and continue on with the rest of the code underneath. Example:

I want to loop through an array until I get a number that is negative:
Code:
for (int i = 0; i < array.length; i++ ){
    if (array[i] < 0) {
       break;
       }
}

Also, it doesn't really matter if you do i++ or ++i for the level of programming you are at. It basically changes the order that i is incremented in.

cheers!
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
The Rig of Power
(18 items)
 
First Build
(13 items)
 
 
CPUMotherboardGraphicsGraphics
Intel i7 3930k Asus P9X79 Pro nVidia 9800 GT nVidia 9800 GT 
RAMHard DriveHard DriveHard Drive
Corsair XMS3 WD Black WD Blue WD Raptor 10,000 RPM 
Hard DriveHard DriveCoolingOS
Corsair Force 3 SSD Seagate Corsiar H80 Windows 7 Ultimate 64-bit 
MonitorKeyboardPowerCase
Dell U2311H Logitech G19 Corsair TX750 Corsair 650D 
MouseAudio
Logitech G500 Logitech G51 
CPUMotherboardGraphicsRAM
Amd Phenom II X3 Asus M4a785TD-V EVO NVIDIA 9800GTX 4 GB G.skill DDR3 @ 1333 mhz 
Hard DriveOSMonitorKeyboard
WD blue250,350(boot,games) WD 1TB black(storage) windows 7 Ultimate 64-bit Dell U2311h Logitech G19 
PowerCaseMouse
500 Watt smilidon Logitech G500 
  hide details  
Reply
post #14 of 23
Thread Starter 
Thank you all! I will be sure to post my code back when finished or if I get stuck on something (hope that doesn't happen).
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
post #15 of 23
Quote:
Originally Posted by Fullinator View Post

For loops are better in situations where you know you have to loop n number of times. In java you can find the length of the array and so you can loop through the entire array using a for loop! Remember that arrays start at index zero!

While loops are better if you are looping until a condition is met or not met. For example: I want the user to input the number 45. I will loop until the input is equal to 45.

There is also a thing called a do while loop. This is basically a while loop but is guaranteed to loop at least once.

Another cool piece of info you might want to know are the continue and break directives. continue will basically skip the rest of the code in the loop and go to the next loop iteration. Break will just stop looping all together and continue on with the rest of the code underneath. Example:

I want to loop through an array until I get a number that is negative:
Code:
for (int i = 0; i < array.length; i++ ){
    if (array[i] < 0) {
       break;
       }
}

Also, it doesn't really matter if you do i++ or ++i for the level of programming you are at. It basically changes the order that i is incremented in.

cheers!

I agree, but partially. Even for beginners I advocate always using ++i (pre-increment) and only using i++ (post-increment) when absolutely necessary. But that's just a little thing of mine (I'd rather save an instruction even though its a huge micro optimization tongue.gif)
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #16 of 23
Thread Starter 
Almost done, I'm testing it and I have a small issue. I have to give output for Total Hours and the Total Charge. I didn't know how to sum the hours array so I did it manually. I'll try to figure it out with another for loop. Not sure what is wrong with the output, the logic seems fine.
Code:
import java.text.DecimalFormat;
import java.util.Scanner;

public class ParkGarage {
        
        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                double[]      cars, hours;
                double        minPrice, maxPrice, minHours, hourIncrementPrice,
                                      totalHours, totalCharge;
                DecimalFormat df;
                
                cars               = new double[5];
                hours              = new double[5];
                minPrice           = 5.00;
                maxPrice           = 12.00;
                minHours           = 2.0;
                hourIncrementPrice = 1.0;
                totalHours         = 0;
                totalCharge        = 0;
                df                 = new DecimalFormat("$###.00");
                
                for(int j = 0; j < 5; ++j) { // With j=0, it asks for car 0:
                        System.out.print("Enter the hours parked for car " + j + ": ");
                        hours[j] = input.nextDouble();
                        
                        if (hours[j] < minHours)
                                hours[j] = minHours;
                        
                        cars[j] = minPrice + (j - minHours) * hourIncrementPrice;
                        
                        if (cars[j] > maxPrice)
                                cars[j] = maxPrice;
                                                
                        totalHours  = hours[0] + hours[1] + hours[2] + hours[3] + hours[4];
                        // If I input 1 for all 5 cars, I get Total Hours 10.0 instead of 5.0   
                        totalCharge = cars[0] + cars[1] + cars[2] + cars[3] + hours[4];
                        // If I input 1 for all 5 cars, I get Total Hours 20.0 instead of 25.0
                }
                
                System.out.println("Total Hours " + totalHours);
                System.out.println("Total Charge " + totalCharge);
        }

}

Edited by Heat Miser - 3/11/14 at 1:53am
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
post #17 of 23
Code:
 System.out.print("Enter the hours parked for car " + j + ": ");

Change to:
Code:
 System.out.print("Enter the hours parked for car " + ( j + 1 ) + ": "); // we just add one to J when outputting to make it look more friendly
Code:
totalHours = hours[0] + hours[1] + hours[2] + hours[3] + hours[4];

Change to:
Code:
totalHours += hours[j]; // same as totalHours = totalHours + hours[j];

You can do the same when you need to sum up the total charge.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #18 of 23
Quote:
Originally Posted by tompsonn View Post

I agree, but partially. Even for beginners I advocate always using ++i (pre-increment) and only using i++ (post-increment) when absolutely necessary. But that's just a little thing of mine (I'd rather save an instruction even though its a huge micro optimization tongue.gif)
Modern compilers would optimise against that automatically anyway. Not that I'm trying to discourage best practices.
Quote:
Originally Posted by Heat Miser View Post

Almost done, I'm testing it and I have a small issue. I have to give output for Total Hours and the Total Charge. I didn't know how to sum the hours array so I did it manually.
Code:
import java.text.DecimalFormat;
import java.util.Scanner;

public class ParkGarage {
        
        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                double[]      cars, hours;
                double        minPrice, maxPrice, minHours, hourIncrementPrice,
                                      totalHours, totalCharge;
                DecimalFormat df;
                
                cars               = new double[5];
                hours              = new double[5];
                minPrice           = 5.00;
                maxPrice           = 12.00;
                minHours           = 2.0;
                hourIncrementPrice = 1.0;
                totalHours         = 0;
                df                 = new DecimalFormat("$###.00");
                
                for(int j = 0; j < 5; ++j) { // With j=0, it asks for car 0:
                        System.out.print("Enter the hours parked for car " + j + ": ");
                        hours[j] = input.nextDouble();
                        
                        if (hours[j] < minHours)
                                hours[j] = minHours;
                        
                        cars[j] = minPrice + (j - minHours) * hourIncrementPrice;
                        
                        if (cars[j] > maxPrice)
                                cars[j] = maxPrice;
                                                
                        totalHours = hours[0] + hours[1] + hours[2] + hours[3] + hours[4];
                        // If I input 1 for all 5 cars, I get Total Hours 10.0 instead of 5.0                                           
                }
                System.out.print("Total Hours " + totalHours);
        }

}
You're right to put the calculation for totalHours inside the loop, but by doing so you don't need to manually specify the indexes of the array because you can just add each index to the existing totalHours.

An example in pseudo-code would be:
Code:
for i 1 to 5
    total = total + item[i]
end for

print "Total: " + total
(there's special operators which will do this for you in Java, but I'll leave you to use them or not to use them depending on what you've been taught thus far)

edit: nevermind, tompsonn has given you the answer anyway. smile.gif
post #19 of 23
Thread Starter 
The only problem I have now is the output. It is completely wrong doh.gif The logic seems fine.
badoutput.PNG 7k .PNG file
Code:
import java.text.DecimalFormat;
import java.util.Scanner;

public class ParkGarage {
        
        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                double[]      cars, hours;
                double        minPrice, maxPrice, minHours, hourIncrementPrice,
                                      totalHours, totalCharge;
                DecimalFormat df;
                
                cars               = new double[5];
                hours              = new double[5];
                minPrice           = 5.00;
                maxPrice           = 12.00;
                minHours           = 2.0;
                hourIncrementPrice = 1.0;
                totalHours         = 0;
                totalCharge        = 0;
                df                 = new DecimalFormat("$###.00");
                
                for(int j = 0; j < 5; ++j) {
                        System.out.print("Enter the hours parked for car " + ( j + 1 ) + ": ");
                        hours[j] = input.nextDouble();
                        
                        if (hours[j] < minHours) {
                                hours[j] = minHours;
                        }
                        cars[j] = minPrice + (j - minHours) * hourIncrementPrice;
                        
                        if (cars[j] > maxPrice) {
                                cars[j] = maxPrice;
                        }                       
                        
                        totalHours  += hours[j];        
                        totalCharge += cars[j];
                }
                
                System.out.println("Total Hours " + totalHours);
                System.out.println("Total Charge " + df.format(totalCharge));

        }

}

Edited by Heat Miser - 3/11/14 at 2:26am
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
My System
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k ASUS P8P67 Deluxe EVGA GTX 570 SC G.SKILL Ripjaws X 8GB 
Hard DriveHard DriveCoolingOS
Crucial M4 Samsung Spinpoint F3 Prolimatech Megahalems Windows 7 Professional 
MonitorKeyboardPowerCase
Samsung P2450H 24" Ducky Shine Blue LED w/ Cherry MX Reds Corsair HX850 FT02B-W 
Mouse
Razer Death Adder 
  hide details  
Reply
post #20 of 23
There's a small mistake...
Code:
cars[j] = minPrice + (j - minHours) * hourIncrementPrice;

Should be (I add brackets for clarity though that's not the mistake)
Code:
cars[j] = minPrice + ( (hours[j] - minHours) * hourIncrementPrice );
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Need help with arrays in Java