Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8093375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:29:28+00:00 2026-06-05T20:29:28+00:00

This program runs just fine, but for some reason when I ask for an

  • 0

This program runs just fine, but for some reason when I ask for an input for name it will only save the first word in the response. For example if I enter “Jon Snow” when I use it later for output it will only show “Jon”.

import java.util.Scanner;

public class help 
{
public static void main (String[] args)
{
    Scanner input = new Scanner(System.in); //object for user input

    //constant
    final double tax = 0.08; //Sales tax

    //variables
    int choice;                 //menu selection/case switch
    String name;                //customer's name   
    String address;             //customer's address
    String email;               //customer's email address
    String item;                //item purchased
    double itemsPurchased;      //number of items purchased
    double itemPrice;           //price of item purchased
    double total;               //total for purchase
    double grandTotal;          //total + tax
    double taxAmount;           //tax of the purchase

    //Menu
    System.out.println("1. Enter Customer Information");
    System.out.println("2. Display Total Bill");
    System.out.println("3. Quit\n");                            
    System.out.print("Enter 1, 2, or 3 to make your selection: ");
    choice = input.nextInt();

    switch(choice){

    //Customer info

    case 1:

        //inputting info
        System.out.println("\nPlease enter the customers information.");

        //name
        System.out.print("Name: "); 
        name = input.next();
        input.nextLine();                                           

        //address
        System.out.print("Address: ");
        address = input.nextLine();

        //email
        System.out.print("Email Adress: ");
        email = input.next();
        input.nextLine();                                           

        //reading info back to user
        System.out.println("\nThe customer has successfully been added to our list with the following information: ");
        System.out.println("Name: " + name);
        System.out.println("Address: " + address);
        System.out.println("Emal: " + email);
        break;                      

    //Customer receipt  

    case 2:

        //name
        System.out.println("");                                     
        System.out.print("Enter customer's name: ");
        name = input.next();
        input.nextLine();                                           

        //name of item purchased
        System.out.print("Enter item purchased: ");
        item = input.next();
        input.nextLine();                                           

        //number of items purchased
        System.out.print("Number of items purchased: ");
        itemsPurchased = input.nextDouble();
        input.nextLine();                                           

        //price of item
        System.out.print("Price of item: ");
        itemPrice = input.nextDouble();
        input.nextLine();                                           

        //defining taxAmount, total, and grandTotal
        total = (itemPrice * itemsPurchased);
        taxAmount = (total*tax);
        grandTotal = total + taxAmount;

        //bill

        System.out.println("");                                                                         
        System.out.println(name);
        System.out.println("");                                                                         
        System.out.printf("%-20s %-15s %-15s\n", "Product Purchased", "Quantity", "Total Cost");            
        System.out.println("");
        System.out.printf("%-20s %-15s %-15s\n", item, itemsPurchased, total);
        System.out.println("");                                                                         
        System.out.printf("%-20s %-15s %-15s\n", "Tax(@8%):", "", taxAmount);
        System.out.printf("%-20s %-15s %-15s\n", "Total Cost:", "", grandTotal);

        break;                      

    //Quit

    case 3:

        System.out.println("End Program");
        break; //void

    //Default statement

    default:
        System.out.print("Invalid value entered.");

    }//end case

}//end main

}//end class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:29:29+00:00Added an answer on June 5, 2026 at 8:29 pm
    name = input.nextLine()
    

    You are not reading the whole line but only the first word.

    For the Scanner class, the next() function reads the next tokenized input while nextLine() retrieves the whole line until the carriage return (\n).

    Eg. "happy days again"
    next() // "happy"
    next() // "days"
    next() // "again"
    
    or,
    
    nextLine() // "happy days again"
    

    EDIT: Try the code below

    input.nextLine(); // IMP: To get the carriage return after choice is typed
    //name
    System.out.println("");                                     
    System.out.print("Enter customer's name: ");
    name = input.nextLine();                                           
    
    //name of item purchased
    System.out.print("Enter item purchased: ");
    item = input.nextLine(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not too sure what to make of this, but program runs just fine in
My app runs just fine in the simulator, but now I have a developers
This program in C runs and compiles well : #ifdef HAVE_CONFIG_H #include <config.h> #endif
So I have a program which runs. This is part of the code: FileName
I have a program which does a system call: latex somefile.latex This runs ok,
This program reads emails (really just a .txt file structured like an email) and
This program takes the first number in a file and indicates how many numbers
This program I use has it's own variables to set when you run it,
This program stores pairs in a map, counting the number of times a word
This program I'm doing is about a social network, which means there are users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.