For some reason my output is not showing right when I run it. I am showing the code and providing a screen shot of what it's doing. It's bunching lines together.

public void requestData()
	{
		System.out.print("What is the model number?");
		modelNumber = scan.nextLine();
		
		System.out.print("What is the camera brand?");
		brand = scan.nextLine();
		
		System.out.print("How many megapixels?");
		megapixels = scan.nextInt();
		
		System.out.print("What type of lens does it have?");
		lensType = scan.nextLine();
				
		System.out.print("How much did it cost?");
		price = scan.nextDouble();
		
		System.out.print("Is it waterproof? True or False");
		isWaterproof = scan.nextBoolean();
		
		System.out.print("What color is the camera?");
		color = scan.nextLine();
		
		System.out.print("What date was it purchased on? MM/DD/YYYY format please");
		purchaseDate = scan.nextLine();
		
	}

[IMG]http://i.imgur.com/NmFN4.png[/IMG]

Recommended Answers

All 9 Replies

Is the enter key throwing it off between reads?
Can you read it all as strings then convert to integer or whatever you need?

I don't believe the enter is messing it up. It works for every other one except for those 2 pictured.

And I guess I could read them all as strings but that would be a lot more work it seems like.

I feel like there's a simple solution I'm missing.

Just tried switching the spot where is jumbles it to a string and it still prints out the same issue.

Can you copy and paste here the console? Instead of an image.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

What is the model number?ZW33P
What is the camera brand?Fuji
How many megapixels?10
What type of lens does it have?How much did it cost?299.99
Is it waterproof? True or Falsetrue
What color is the camera?What date was it purchased on? MM/DD/YYYY format please

I think this is what you wanted?

Can you explain what you want to change? Post a sample of how you want it to look like.

I would like it to look like this:


What is the model number?ZW33P
What is the camera brand?Fuji
How many megapixels?10
What type of lens does it have?
How much did it cost?299.99
Is it waterproof? True or Falsetrue
What color is the camera?
What date was it purchased on? MM/DD/YYYY format please

As it is now It won't let you enter information for the lens type or color

One of the tricks/problems with the Scanner class is that it holds the line-end character from the Enter key in its buffer. When you call nextLine that line-end character is read and returned. Try experimenting by adding calls to nextLine() to clear/read the line-end character left from from the preceding user input before you try to get data agaim,

commented: Very helpful! +1

That worked! Thank you very much!

You're welcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.