Due Date: May 2, 2024
The Scanner class
in Java is a part of the java.util package and
is used to read input from various sources,
including user input from the console, files,
and strings. It provides methods to parse
primitive types and strings using regular
expressions. The Scanner breaks its input
into tokens using a delimiter, which by default
matches whitespace. It's commonly used to
read text files or console input in a controlled,
tokenized manner.
For example, when reading from the console,
you can create a Scanner object to read each
word or line of input:
Scanner scanner = new Scanner(System.in);
String userInput = scanner.nextLine();
Similarly, to read from a file, you can pass a
File object to the Scanner constructor:
Scanner fileScanner = new Scanner(new File("input.txt"));
The Scanner class is versatile and user-
friendly, offering methods like nextInt(),
nextDouble(), nextLine(), etc., to read specific
types of data. However, it's important to
handle exceptions and ensure that resources
like files are properly closed after use to
prevent resource leaks.
Your files will be:
PX_Scanner_lastname.java (Actual Java program)
PX_Scanner_lastname.png (Screen shot of the program in the Eclipse IDE)
PX_Scanner_lastname.mp4 (Video)
(Video should include an explanation of the program
and showing it running successfully)
Be sure to drop these files into google classroom.
Here's what the program will do:
Due Date: May 6, 2024
Java program to calculate Molar Mass
How to Calculate Molar Mass of a Chemical Compound
To calculate the molar mass of a chemical compound:
1. Identify the Formula: Note the compound's molecular formula, e.g., H2O.
2. Get Atomic Masses: Use a periodic table to find
the mass of each element in grams per mole (g/mol).
3. Count Atoms: Count how many atoms of
each element are in the formula.
4. Calculate: Multiply each element's
atomic mass by its count, then sum these values.
For instance, water (H2O) has a molar mass
of 18.016 g/mol, calculated as (2 x 1.008) + 16.00.
To learn more about calculating Molar Mass click here.
Your files will be:
PX_MolarMass_lastname.java (Actual Java program)
PX_MolarMass_lastname.png (Screen shot of the
program in the Eclipse IDE)
PX_MolarMass_lastname.mp4 (Video)
(Video should include an explanation of the program
and showing it running successfully)
Be sure to drop these files into google classroom.
Click here to read the specs for this program.
Click here to read the Pseudocode for this program.
Click here to learn about HashMap with examples.
(You will use the HashMap in this assignments.)
I have the program code below with a section of code missing.
**** Section 1 *****
**** Section 2 *****
**** Missing code ****
**** Section 3 *****
**** Section 4 *****
KP Java Programming – Course Outline
Section 1 - Getting Started
Java Basics
Data Types
Arrays and References
Operators and Constructs
Java Objects
Dynamic Memory Allocation
Java Methods
Java Strings
Section 2 - Classes and Objects
Class Design
Fields and Access Control
Constructors
Method Overloading
Static Methods
Inheritance
Method Overriding
Using
final
and
super
Abstract Classes and Methods
Dynamic Binding
Polymorphism
Section 3 - Working with Classes
Using
instanceof
Interfaces
Exception Handling
Exception Objects
throw points, throws clause
try, catch, finally
Section 4 - User Interfaces
Window Applications
Layout Managers
Event Handlers and Listeners
Anonymous Classes and Lambdas
Java Swing APIs
Basic GUI Controls
Menus and MenuBars
Section 5 - Generics and Collections
Why Use Generics?
Generic Classes and Interfaces
Generic Iterators
Collections
ArrayList, LinkedList, HashMap
Section 6 - Threads
Thread States
Extending the
Thread
class
Timer Thread
Implementing the
Runnable
interface
Section 7 - File I/O
Input and Output Streams
Binary and Text Files
Files and Directory Methods
Appendix
Java Language
JavaFX