Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This week we will cover chapter 2. Chapter 2 introduces the eight primitive data types in the Java language. You will learn to work with
This week we will cover chapter 2. Chapter 2 introduces the eight primitive data types in the Java language. You will learn to work with integer, floating-point, Boolean, and character values. Arithmetic and comparison operators are introduced. Finally, you will learn to create input and confirm dialog boxes using the JOptionPane class.
Here are notes I took while reading and working through Chapter 2.
- Variable names must use camel casing. Camel casing is where the first word of the variable name should begin with a lowercase letter and all first letters of subsequent words should be uppercase. (ex. firstName)
- Named constants must be preceded by the final keyword and consist of all uppercase letters, separated by an underscore and have a value assigned to it. (ex. final int NUMBER_OF_DEPTS = 20)
- When using the Scanner class:
- System.in object only reads bytes.
- Scanner class is used to allow the System.in object to accept data of other types.
- Scanner class contains methods for accepting each data type except char.
- nextLine() method should be used to accept the Enter key when following one of the other input methods. (pages 81-83)
- Use the Scanner class when writing the NauticalMiles and NauticalMilesInteractive applications. The JOptionPane class should be used when writing the SammysRentalPrice application and all other programming assignments for the rest of the semester.
Questions
- Why should you use the JOptionPane class instead of the Scanner class when interacting with the user?
- Why do you think it is important to have a variety of different data types for integers and floating-point numbers?
- What is type casting and why might it be necessary to perform it?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started