Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Needing help with an assignent
New Posts  All Forums:Forum Nav:

Needing help with an assignent

post #1 of 5
Thread Starter 
I know what I have to do for the assignment, I understand that fully.

Basically I am stuck on how to get it to use the scanner class to scan a string of text (recording a name)
So far I have:
Code:
int name;
                Scanner scanner;
                        scanner = new Scanner (System.in);
                        System.out.println("Please enter your name (Spaces are permitted)");
                        name = scanner.nextstring();
                        System.out.println("Your name is:" + name);

The "scanner" is called "Sc1" for Scanner 1
name = scanner.nextstring();
The compiler keeps telling me that the "." that is enlarged and bolded can not be found.
Edited by Matt-Matt - 3/31/13 at 11:35pm
 
Seven Seven Five
(12 items)
 
 
CPUMotherboardGraphicsRAM
Convertible i5 3570k (De-Lidded) Gigabyte Z77x-D3H XFX R9 290 With Koolance Block (1179/1450) 16GB G-Skill Ares 1866 
Hard DriveHard DriveHard DriveHard Drive
Samsung 840 Evo Seagate Barracuda 2TB Western Digital Green 2TB Samsung Spinpoint 1TB 
Hard DriveOptical DriveCoolingCooling
Western Digital Green 640GB 2x OEM DVD Drives Heatkiller Rev 3.0 XSPC RX360 
CoolingCoolingCoolingOS
Laing D5 + XSPC Res Primochill Bloodshed Red Tubing Koolance Fullcover R9 290x Block Windows 10 Pro x64 
MonitorMonitorMonitorKeyboard
Asus VEH228H Asus VE228H Aavara TS742 Dual Monitor Stand Ducky Shine II Cherry Blue RED Backlit Mechanic... 
PowerCaseMouseMouse Pad
Silverstone Strider 850W HAF 932 Logitech G400 Gigabyte Ghost 
AudioOther
Microlab Solo6c Logitech C100 Webcam 
  hide details  
Reply
 
Seven Seven Five
(12 items)
 
 
CPUMotherboardGraphicsRAM
Convertible i5 3570k (De-Lidded) Gigabyte Z77x-D3H XFX R9 290 With Koolance Block (1179/1450) 16GB G-Skill Ares 1866 
Hard DriveHard DriveHard DriveHard Drive
Samsung 840 Evo Seagate Barracuda 2TB Western Digital Green 2TB Samsung Spinpoint 1TB 
Hard DriveOptical DriveCoolingCooling
Western Digital Green 640GB 2x OEM DVD Drives Heatkiller Rev 3.0 XSPC RX360 
CoolingCoolingCoolingOS
Laing D5 + XSPC Res Primochill Bloodshed Red Tubing Koolance Fullcover R9 290x Block Windows 10 Pro x64 
MonitorMonitorMonitorKeyboard
Asus VEH228H Asus VE228H Aavara TS742 Dual Monitor Stand Ducky Shine II Cherry Blue RED Backlit Mechanic... 
PowerCaseMouseMouse Pad
Silverstone Strider 850W HAF 932 Logitech G400 Gigabyte Ghost 
AudioOther
Microlab Solo6c Logitech C100 Webcam 
  hide details  
Reply
post #2 of 5
Please be careful to specify the language in which you're coding in the beginning of the thread's title smile.gif

Now, is that Java?
My Rig
(14 items)
 
Ex-wife's Rig
(15 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 4460 AsRock H81M-DG4 Sapphire Rx470 Platinum KVR 1600 16Gb 
Hard DriveHard DriveCoolingOS
2x Seagate 3Tb Samsung 850 EVO 120 Scythe Ninja 3 Rev.B Windows 10 Pro 
MonitorKeyboardPowerCase
Fujitsu Siemens A17-2A Logitech K280e SuperFlower SF-550K12XP Thermaltake Versa H25 
MouseAudio
Logitech G402 Sony MDR XD150 
CPUMotherboardGraphicsRAM
Athlon 750K 4.0Ghz AsRock FM2A75 Pro4+ Sapphire R9 270X Dual-X Kingston 2x4Gb 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 850 EVO 120  Western Digital 320Gb LiteON DVD-RW CoolerMaster Hyper Z600 
OSMonitorKeyboardPower
Windows 7 Pro x64 Toshiba 32" FullHD TV Logitech FSP Hexa 550 
CaseMouse
DeLUX Logitech 
  hide details  
Reply
My Rig
(14 items)
 
Ex-wife's Rig
(15 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 4460 AsRock H81M-DG4 Sapphire Rx470 Platinum KVR 1600 16Gb 
Hard DriveHard DriveCoolingOS
2x Seagate 3Tb Samsung 850 EVO 120 Scythe Ninja 3 Rev.B Windows 10 Pro 
MonitorKeyboardPowerCase
Fujitsu Siemens A17-2A Logitech K280e SuperFlower SF-550K12XP Thermaltake Versa H25 
MouseAudio
Logitech G402 Sony MDR XD150 
CPUMotherboardGraphicsRAM
Athlon 750K 4.0Ghz AsRock FM2A75 Pro4+ Sapphire R9 270X Dual-X Kingston 2x4Gb 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 850 EVO 120  Western Digital 320Gb LiteON DVD-RW CoolerMaster Hyper Z600 
OSMonitorKeyboardPower
Windows 7 Pro x64 Toshiba 32" FullHD TV Logitech FSP Hexa 550 
CaseMouse
DeLUX Logitech 
  hide details  
Reply
post #3 of 5
I'm not completely sure about that error, but name should be a String type, not an int type, and the method is scanner.next(), not scanner.nextString(). Can you post the complete code you have so far?

Also, I assume this is Java, what version are you using? Also, what IDE?
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Reply
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Reply
post #4 of 5
**Assuming Java**

Well, to start with, you have the "name" variable initialized as an "int" (integer). You can't place letters into an integer. The name variable is initialized to be the wrong data type.

Additionally, to my recollection, there is no "nextstring()" ... there is a "next()" however which gets the next string that's inputted.

Heck, even using "next()" may not be correct. Test your program, try a full name, ie first and last with a space in between. Look at what happens, some tweaking may need to be done smile.gif

Lastly, which IDE are you using? I'm quite partial to NetBeans. Which while typing in "scanner." (line 5 in the code you gave) will list all the possible methods that can be tacked on to perform specific functions, as well as what they do (with documentation).
    
CPUMotherboardGraphicsRAM
Intel i7 4790k Asus Maximus Impact VII Z97 EVGA GTX 780 Classified Crucial Ballistix VLP 2x8GB 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 830 256GB Seagate 1TB SSHD Lite-On eNAU108-111 Thermalright Ultra Extreme Black 
OSMonitorKeyboardPower
Windows 8.1 Professional Asus PB278Q Das Keyboard Ultimate 4 Seasonic 760W Platinum 
CaseMouseMouse PadAudio
CaseLabs Nova X2M Logitech G602 Razer Scarab Asus Sonar Impact II + AudioEngine A2 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel i7 4790k Asus Maximus Impact VII Z97 EVGA GTX 780 Classified Crucial Ballistix VLP 2x8GB 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 830 256GB Seagate 1TB SSHD Lite-On eNAU108-111 Thermalright Ultra Extreme Black 
OSMonitorKeyboardPower
Windows 8.1 Professional Asus PB278Q Das Keyboard Ultimate 4 Seasonic 760W Platinum 
CaseMouseMouse PadAudio
CaseLabs Nova X2M Logitech G602 Razer Scarab Asus Sonar Impact II + AudioEngine A2 
  hide details  
Reply
post #5 of 5
Thread Starter 
Quote:
Originally Posted by Munkypoo7 View Post

**Assuming Java**

Well, to start with, you have the "name" variable initialized as an "int" (integer). You can't place letters into an integer. The name variable is initialized to be the wrong data type.

Additionally, to my recollection, there is no "nextstring()" ... there is a "next()" however which gets the next string that's inputted.

Heck, even using "next()" may not be correct. Test your program, try a full name, ie first and last with a space in between. Look at what happens, some tweaking may need to be done smile.gif

Lastly, which IDE are you using? I'm quite partial to NetBeans. Which while typing in "scanner." (line 5 in the code you gave) will list all the possible methods that can be tacked on to perform specific functions, as well as what they do (with documentation).

Quote:
Originally Posted by Waffleboy View Post

I'm not completely sure about that error, but name should be a String type, not an int type, and the method is scanner.next(), not scanner.nextString(). Can you post the complete code you have so far?

Also, I assume this is Java, what version are you using? Also, what IDE?

Quote:
Originally Posted by ronnin426850 View Post

Please be careful to specify the language in which you're coding in the beginning of the thread's title smile.gif

Now, is that Java?

Thanks guys! Yeah i forgot to mention it was java!
I'll read through your comments later about this, as I've figured out a better way to do it (sc.nextchar) - Gotta go over the lecture to understand how it all goes.
I've been working on an assignment that I forgot about (Due next week), it was just asking to enter Integers, Doubles and a Boolean which I have working. I'm having trouble combining them all into one java file but I'll get a mate to help me in real life. +Rep to you all smile.gif

I'm using the Java JDK 1.7.0.17 (64 bit), I'm also using JCreator to write my programs (that makes no difference I know) and i'm using environment variables to link CMD prompt to the JDK.

Yes, thankyou for mentioning that it's scanner.next(), I just assumed from scanner.nextInt etc. I also did see the other silly mistakes I made (Declaring an Int type and then trying to put a string of text in it. #embarassed tongue.gif
Edited by Matt-Matt - 4/1/13 at 11:27pm
 
Seven Seven Five
(12 items)
 
 
CPUMotherboardGraphicsRAM
Convertible i5 3570k (De-Lidded) Gigabyte Z77x-D3H XFX R9 290 With Koolance Block (1179/1450) 16GB G-Skill Ares 1866 
Hard DriveHard DriveHard DriveHard Drive
Samsung 840 Evo Seagate Barracuda 2TB Western Digital Green 2TB Samsung Spinpoint 1TB 
Hard DriveOptical DriveCoolingCooling
Western Digital Green 640GB 2x OEM DVD Drives Heatkiller Rev 3.0 XSPC RX360 
CoolingCoolingCoolingOS
Laing D5 + XSPC Res Primochill Bloodshed Red Tubing Koolance Fullcover R9 290x Block Windows 10 Pro x64 
MonitorMonitorMonitorKeyboard
Asus VEH228H Asus VE228H Aavara TS742 Dual Monitor Stand Ducky Shine II Cherry Blue RED Backlit Mechanic... 
PowerCaseMouseMouse Pad
Silverstone Strider 850W HAF 932 Logitech G400 Gigabyte Ghost 
AudioOther
Microlab Solo6c Logitech C100 Webcam 
  hide details  
Reply
 
Seven Seven Five
(12 items)
 
 
CPUMotherboardGraphicsRAM
Convertible i5 3570k (De-Lidded) Gigabyte Z77x-D3H XFX R9 290 With Koolance Block (1179/1450) 16GB G-Skill Ares 1866 
Hard DriveHard DriveHard DriveHard Drive
Samsung 840 Evo Seagate Barracuda 2TB Western Digital Green 2TB Samsung Spinpoint 1TB 
Hard DriveOptical DriveCoolingCooling
Western Digital Green 640GB 2x OEM DVD Drives Heatkiller Rev 3.0 XSPC RX360 
CoolingCoolingCoolingOS
Laing D5 + XSPC Res Primochill Bloodshed Red Tubing Koolance Fullcover R9 290x Block Windows 10 Pro x64 
MonitorMonitorMonitorKeyboard
Asus VEH228H Asus VE228H Aavara TS742 Dual Monitor Stand Ducky Shine II Cherry Blue RED Backlit Mechanic... 
PowerCaseMouseMouse Pad
Silverstone Strider 850W HAF 932 Logitech G400 Gigabyte Ghost 
AudioOther
Microlab Solo6c Logitech C100 Webcam 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Needing help with an assignent