Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Newb Java Programming Help
New Posts  All Forums:Forum Nav:

Newb Java Programming Help

post #1 of 6
Thread Starter 
How do you indent lines and limit decimal places?

I have never seen it done - I am new - I have no idea where to start looking (Googling just confused me)...

This is what my output currently looks like:


I need to limit the dollar amounts to two decimal places, and every line below "Summary of Cost Calculations" needs to be indented, but I am clueless as to how to go about this...

Any help?

Thanks
Computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k @ Stock EVGA Z75 EVGA GTX 680 @ Stock 16GB Corsair Vengeance 1600 
Hard DriveOSMonitorPower
60GB Vertex 2, 2x256GB Vertex 4 RAID0, 2x1TB WD... Windows 8 Pro 64-bit 28" LED Seasonic X-850 
Case
Corsair 600T White 
  hide details  
Reply
Computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k @ Stock EVGA Z75 EVGA GTX 680 @ Stock 16GB Corsair Vengeance 1600 
Hard DriveOSMonitorPower
60GB Vertex 2, 2x256GB Vertex 4 RAID0, 2x1TB WD... Windows 8 Pro 64-bit 28" LED Seasonic X-850 
Case
Corsair 600T White 
  hide details  
Reply
post #2 of 6
This may be helpful. I'm going to do some more research. I feel like I've done this before.

Here is a tutorial.

As for indenting, just use the tab escape character.

I can tell this is a school assignment, so hopefully you'll actually read those articles rather than just find the answer.

Nice motherboard, by the way
Edited by Wiremaster - 1/13/11 at 11:13am
Lappy
(9 items)
 
  
CPUMotherboardGraphicsRAM
P8700 Toshiba GM45 ICH9-M Intel 4 Series Samsung M4 
Hard DriveOptical DriveOSCase
Hitachi HTS723232L9A360 Matshita UJ880AS Windows 7 Pro 64 Toshiba A500-6621 
Mouse
Mionix Naos 5000 
  hide details  
Reply
Lappy
(9 items)
 
  
CPUMotherboardGraphicsRAM
P8700 Toshiba GM45 ICH9-M Intel 4 Series Samsung M4 
Hard DriveOptical DriveOSCase
Hitachi HTS723232L9A360 Matshita UJ880AS Windows 7 Pro 64 Toshiba A500-6621 
Mouse
Mionix Naos 5000 
  hide details  
Reply
post #3 of 6
Thread Starter 
Quote:
Originally Posted by Wiremaster View Post
This may be helpful. I'm going to do some more research. I feel like I've done this before.

Here is a tutorial.

As for indenting, just use the tab escape character.

I can tell this is a school assignment, so hopefully you'll actually read those articles rather than just find the answer.

Nice motherboard, by the way
Can you give me like an example of what that type of code would look like (for the decimal points)...? I am utterly confused by what that article is talking about (I am very new to programming - like less than a week)...

Thanks
Computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k @ Stock EVGA Z75 EVGA GTX 680 @ Stock 16GB Corsair Vengeance 1600 
Hard DriveOSMonitorPower
60GB Vertex 2, 2x256GB Vertex 4 RAID0, 2x1TB WD... Windows 8 Pro 64-bit 28" LED Seasonic X-850 
Case
Corsair 600T White 
  hide details  
Reply
Computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k @ Stock EVGA Z75 EVGA GTX 680 @ Stock 16GB Corsair Vengeance 1600 
Hard DriveOSMonitorPower
60GB Vertex 2, 2x256GB Vertex 4 RAID0, 2x1TB WD... Windows 8 Pro 64-bit 28" LED Seasonic X-850 
Case
Corsair 600T White 
  hide details  
Reply
post #4 of 6
Later... I myself have to go to class.

For now, bump.
Lappy
(9 items)
 
  
CPUMotherboardGraphicsRAM
P8700 Toshiba GM45 ICH9-M Intel 4 Series Samsung M4 
Hard DriveOptical DriveOSCase
Hitachi HTS723232L9A360 Matshita UJ880AS Windows 7 Pro 64 Toshiba A500-6621 
Mouse
Mionix Naos 5000 
  hide details  
Reply
Lappy
(9 items)
 
  
CPUMotherboardGraphicsRAM
P8700 Toshiba GM45 ICH9-M Intel 4 Series Samsung M4 
Hard DriveOptical DriveOSCase
Hitachi HTS723232L9A360 Matshita UJ880AS Windows 7 Pro 64 Toshiba A500-6621 
Mouse
Mionix Naos 5000 
  hide details  
Reply
post #5 of 6
This may help you out, I haven't compiled it, but don't think it should have errors...

Code:
static public String decFormat (double val){
DecimalFormat twoDec = new DecimalFormat("###.##"); String result = twoDec.format(val); return result;}
Then to call the method in main, assuming you have a double named price:
Code:
System.out.println("\ Student Price: $" +decFormat(price) );
    
CPUMotherboardGraphicsGraphics
i7 2600k Asus P8P67 Pro 2x EVGA 580GTX 3GB 2x Saphire 7970 Vapor-x GHz edition (alternate) 
RAMHard DriveHard DriveCooling
16GB G.Skill 2133 CAS9 Hitachi 3tb Corsair M4 128 CM 212+ 
OSMonitorMonitorKeyboard
Arch Linux, OSX, Win7x64 Dell U3011  HP LP3065 Leopold Mechanical Blue 
PowerCaseMouseAudio
Seasonic X1250 Modular Corsair 750d Razer Deathadder V3.5? Bose companion 3 Series II 
Audio
Sennheiser HD-280 Pro 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
i7 2600k Asus P8P67 Pro 2x EVGA 580GTX 3GB 2x Saphire 7970 Vapor-x GHz edition (alternate) 
RAMHard DriveHard DriveCooling
16GB G.Skill 2133 CAS9 Hitachi 3tb Corsair M4 128 CM 212+ 
OSMonitorMonitorKeyboard
Arch Linux, OSX, Win7x64 Dell U3011  HP LP3065 Leopold Mechanical Blue 
PowerCaseMouseAudio
Seasonic X1250 Modular Corsair 750d Razer Deathadder V3.5? Bose companion 3 Series II 
Audio
Sennheiser HD-280 Pro 
  hide details  
Reply
post #6 of 6
Thread Starter 
I think I made this way to confusing for myself by not stating that I was looking for two decimal places in the output only... And after digging and digging... I found a very simple way to do it...

Code:
System.out.printf("\ Sudent price: $%.2f \
", costToStudent);
I brought that on myself by not specifying I guess... I think what everyone here was trying to explain was a way to make every decimal in the entire program rounded...

Thanks for the help guys!
Computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k @ Stock EVGA Z75 EVGA GTX 680 @ Stock 16GB Corsair Vengeance 1600 
Hard DriveOSMonitorPower
60GB Vertex 2, 2x256GB Vertex 4 RAID0, 2x1TB WD... Windows 8 Pro 64-bit 28" LED Seasonic X-850 
Case
Corsair 600T White 
  hide details  
Reply
Computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k @ Stock EVGA Z75 EVGA GTX 680 @ Stock 16GB Corsair Vengeance 1600 
Hard DriveOSMonitorPower
60GB Vertex 2, 2x256GB Vertex 4 RAID0, 2x1TB WD... Windows 8 Pro 64-bit 28" LED Seasonic X-850 
Case
Corsair 600T White 
  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 › Newb Java Programming Help