Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Introduction to Java
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Related Services

Bookmark and Share
Lecture Comments (4)

0 answers

Post by Mirical Williams-Causton on December 1, 2013

do
{
//User inputs whether they want to add a customer, view a customer, or end the program
System.out.println("
Main Menu
1. Add new customer
2. View customer records
3. Exit program");
chChoice = (char) System.in.read();

if (chChoice == '1')
{
//If user chooses choice one, then it would take the user to the add a customer section
System.out.println("You have chosen to add a customer to the current records.");
//Choice One - Add a Customer
//User inputs the customer's name
System.out.println("Enter customer's name: ");
chName = (char) System.in.read();

while ((chName >= 'A' && chName <= 'Z') || (chName >= 'a' && chName <= 'z'))
{
strName += chName;
chName = (char) System.in.read();
}

System.out.println("Customer's Name: " + strName);
}
I am having problems with this code, in high school it's part of a program, and i was applying concepts that we used and what you have taught me but it would go through the choice and when it hits enter customer name, it stops why ?

0 answers

Post by Dante Oakley on September 23, 2013

Victor it is if you are wondering this is very late.

PS- I am a tenth grader taking APCS in high school, this is very brutal :D

1 answer

Last reply by: Dante Oakley
Mon Sep 23, 2013 7:07 PM

Post by Victor Niu on September 8, 2012

When I did the divide by 0 program, it finished successfully, and returned Infinity. Is this a new feature of Java?

Input, Output, & Errors

  • The Scanner class provides a convenient way to get user input
  • Use System.out.print and System.out.println to produce text output
  • There are three escape sequences you need to know: (newline character), \” (double quote character), and \ (backslash character)
  • Exceptions provide a way of gracefully dealing with unexpected conditions
  • There are six types of exceptions you need to know about

Input, Output, & Errors

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Roadmap 0:11
  • Getting Input from the User 0:42
    • For AP Questions, Will Look Like One of the Following
    • One Method of Getting Input From the User
    • Scanner Class
  • Providing Output to the User 4:38
    • Only 2 Included in AP Subset
    • Example: Print Two Strings on the Same Line
    • Example: Print a String and an Integer
    • Example: Print a Blank Line
    • Java Code Example
  • Escape Sequences 11:10
    • Backslash Character Followed by One or More Additional Characters
    • Newline Character
    • Double Quote Character
    • Backslash Character
    • Java Code Examples: Printing Escape Sequences
  • Exception Handling 16:25
    • Describe As
    • Exceptions Within the AP Subset That Provides Structured Way to Handle Errors
    • Java Code Example
  • Summary 22:21