Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How would you write this in Java?
New Posts  All Forums:Forum Nav:

How would you write this in Java? - Page 2

post #11 of 34
Thread Starter 
ah. i didn't see that post beforehand
post #12 of 34
Thread Starter 
well since i have everyone here I might as well ask my other question.....

for the 2nd part of this project, I have to take in 3 grades and average them together to give a letter grade.

For example... the user inputs, a 100, 85, and 96. I need to take the average (in a separate class) of those 3 (in this case a 93) and use the grading scale to assign that average a letter grade (A=90-100 B=80-89.9, C=70-79.9 and so on).

how do I set it up so that the user can input all 3 grades at one time, rather then 3 different inputs. is it just scan=nextLine();
post #13 of 34
ok, you need to be clear about what you're asking. (and I'm not trying to put you down, I see this happen with a lot of new programmers)

try thinking about your requirements, and how you will fulfill them in logical steps, as part of the final working program.

write out every step the user is going to take when they try to use your program.

Do you want:
A)
1. user starts program
2. user gets asked for 3 grades
3. user types "100 93 85" then presses "ENTER"
4. user gets grade

or
B)
1. user starts program
2. user gets asked for 3 grades
3. user types "100" presses ENTER
4. user types "93" presses ENTER
5. user types "85" then presses ENTER
6. user gets grade

different technique for each case. how would you like it to work?
My AMD&nVidia&ATI
(13 items)
 
  
CPUMotherboardGraphicsRAM
1090T 3.8 @ 1.4v Crosshair IV Formula Sapphire 6850 850/4000 + 9800GT PhysX 8GB HyperX 1600 
Hard DriveOSPowerCase
120GB Solid 3 Boot - 1TB WD Black Windows 7 Ultimate Antec TruePower 750 HAF 932 
  hide details  
Reply
My AMD&nVidia&ATI
(13 items)
 
  
CPUMotherboardGraphicsRAM
1090T 3.8 @ 1.4v Crosshair IV Formula Sapphire 6850 850/4000 + 9800GT PhysX 8GB HyperX 1600 
Hard DriveOSPowerCase
120GB Solid 3 Boot - 1TB WD Black Windows 7 Ultimate Antec TruePower 750 HAF 932 
  hide details  
Reply
post #14 of 34
no, nextLine() will require the user to hit enter after each value. it will also make you parse each input. since you are expecting ints, use nextInt().
you can do something like this:

Code:
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()){
    int i = sc.nextInt();

    //... store i somewhere...
}
iirc, you need to terminate this kind of input loop with a end-of-file character. this would be Ctrl+D (unix) or Ctrl+Z (windows).
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
post #15 of 34
Thread Starter 
Sorry for the confusion. I can have the user input the grades either at one time, OR separately. I want them to enter the grades like case A in your post. like this:

A)
1. user starts program
2. user gets asked for 3 grades
3. user types "100 93 85" then presses "ENTER"
4. user gets grade
post #16 of 34
Quote:
Originally Posted by unfbilly11 View Post
Sorry for the confusion. I can have the user input the grades either at one time, OR separately. I want them to enter the grades like case A in your post. like this:

A)
1. user starts program
2. user gets asked for 3 grades
3. user types "100 93 85" then presses "ENTER"
4. user gets grade
Since inputting that all together makes it together (unless there's something I haven't learned) I'd use the substring method to search for spaces and parse each substring as it's own integer then calculating it. What's important to know though, is there going to be a set number of scores to enter or should the program calculate automatically for as many scores as there are?
Tiny Fun
(8 items)
 
4P Folding Rig 1
(16 items)
 
4P Folding Rig 2
(11 items)
 
CPUMotherboardGraphicsRAM
i7-4770K @ 4.0GHz MSI Z87I EVGA GTX 660 Ti Corsair Vengeance 16GB 
Hard DriveCoolingOSCase
Samsung 840 Pro 256GB Swiftech Apogee Drive II Windows 8 Enterprise x64 Cooler Master Elite 120 Advanced 
CPUCPUCPUCPU
AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core 
MotherboardGraphicsRAMHard Drive
SuperMicro H8QGi+-F Matrox G200eW 16x2 (32GB) Crucial Ballistix DDR3 1600MHz Crucial C300 64GB 
OSPowerCase
Linux Mint 15 Cinnamon 64-bit Enermax Galaxy Evo 1250W Spotswood Tech Tray 
CPUCPUCPUCPU
AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz 
MotherboardGraphicsRAMHard Drive
Supermicro H8QGL-IF+ Matrox G200eW Kingston Server 16x1GB DDR3 Corsair Nova 32GB 
OSPower
Linux Mint 15 Cinnamon 64-bit Cooler Master Silent Pro 1000W 
  hide details  
Reply
Tiny Fun
(8 items)
 
4P Folding Rig 1
(16 items)
 
4P Folding Rig 2
(11 items)
 
CPUMotherboardGraphicsRAM
i7-4770K @ 4.0GHz MSI Z87I EVGA GTX 660 Ti Corsair Vengeance 16GB 
Hard DriveCoolingOSCase
Samsung 840 Pro 256GB Swiftech Apogee Drive II Windows 8 Enterprise x64 Cooler Master Elite 120 Advanced 
CPUCPUCPUCPU
AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core 
MotherboardGraphicsRAMHard Drive
SuperMicro H8QGi+-F Matrox G200eW 16x2 (32GB) Crucial Ballistix DDR3 1600MHz Crucial C300 64GB 
OSPowerCase
Linux Mint 15 Cinnamon 64-bit Enermax Galaxy Evo 1250W Spotswood Tech Tray 
CPUCPUCPUCPU
AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz 
MotherboardGraphicsRAMHard Drive
Supermicro H8QGL-IF+ Matrox G200eW Kingston Server 16x1GB DDR3 Corsair Nova 32GB 
OSPower
Linux Mint 15 Cinnamon 64-bit Cooler Master Silent Pro 1000W 
  hide details  
Reply
post #17 of 34
Thread Starter 
there is going to be a set number of 3 scores.
post #18 of 34
Quote:
Originally Posted by LemonSlice View Post
Since inputting that all together makes it together (unless there's something I haven't learned) I'd use the substring method to search for spaces and parse each substring as it's own integer then calculating it. What's important to know though, is there going to be a set number of scores to enter or should the program calculate automatically for as many scores as there are?
did everybody just miss my post?

why would you use substrings when a scanner will detect ints and auto parse them? or am i missing something here lol?
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
post #19 of 34
Quote:
Originally Posted by travesty View Post
did everybody just miss my post?

why would you use substrings when a scanner will detect ints and auto parse them? or am i missing something here lol?
Yep I missed that . Epic facepalm on my part, being a new programmer too
Tiny Fun
(8 items)
 
4P Folding Rig 1
(16 items)
 
4P Folding Rig 2
(11 items)
 
CPUMotherboardGraphicsRAM
i7-4770K @ 4.0GHz MSI Z87I EVGA GTX 660 Ti Corsair Vengeance 16GB 
Hard DriveCoolingOSCase
Samsung 840 Pro 256GB Swiftech Apogee Drive II Windows 8 Enterprise x64 Cooler Master Elite 120 Advanced 
CPUCPUCPUCPU
AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core 
MotherboardGraphicsRAMHard Drive
SuperMicro H8QGi+-F Matrox G200eW 16x2 (32GB) Crucial Ballistix DDR3 1600MHz Crucial C300 64GB 
OSPowerCase
Linux Mint 15 Cinnamon 64-bit Enermax Galaxy Evo 1250W Spotswood Tech Tray 
CPUCPUCPUCPU
AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz 
MotherboardGraphicsRAMHard Drive
Supermicro H8QGL-IF+ Matrox G200eW Kingston Server 16x1GB DDR3 Corsair Nova 32GB 
OSPower
Linux Mint 15 Cinnamon 64-bit Cooler Master Silent Pro 1000W 
  hide details  
Reply
Tiny Fun
(8 items)
 
4P Folding Rig 1
(16 items)
 
4P Folding Rig 2
(11 items)
 
CPUMotherboardGraphicsRAM
i7-4770K @ 4.0GHz MSI Z87I EVGA GTX 660 Ti Corsair Vengeance 16GB 
Hard DriveCoolingOSCase
Samsung 840 Pro 256GB Swiftech Apogee Drive II Windows 8 Enterprise x64 Cooler Master Elite 120 Advanced 
CPUCPUCPUCPU
AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core AMD Opteron 6274 ES 2.2GHz 16-Core 
MotherboardGraphicsRAMHard Drive
SuperMicro H8QGi+-F Matrox G200eW 16x2 (32GB) Crucial Ballistix DDR3 1600MHz Crucial C300 64GB 
OSPowerCase
Linux Mint 15 Cinnamon 64-bit Enermax Galaxy Evo 1250W Spotswood Tech Tray 
CPUCPUCPUCPU
AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz AMD Opteron 6176 SE 12-Core 2.3GHz 
MotherboardGraphicsRAMHard Drive
Supermicro H8QGL-IF+ Matrox G200eW Kingston Server 16x1GB DDR3 Corsair Nova 32GB 
OSPower
Linux Mint 15 Cinnamon 64-bit Cooler Master Silent Pro 1000W 
  hide details  
Reply
post #20 of 34
Thread Starter 
I think I just about have it.
hang on...editing...
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How would you write this in Java?