Lab 4 - Loops and Files
Objectives: During this lab, students will learn how to:
- Declare variables and select the appropriate data type
- Read from and write into a text file
- Apply loops for repeating processes
- Test the program to validate the logic.
Introduction:
In Lab 4, you will implement the following:
Write a program in Java that performs the following tasks:
Task 1: Ask the user to input a positive number N. Keep asking for a positive number if the number entered by the user is not positive.
Task 2: Create N random numbers (positive integers) in a loop and save them in a text file called "Numbers.txt".
Task 3: Create a histogram by counting the occurrences of each number from "Numbers.txt" and save it in a text file called "Histogram.txt".
Important: Your program should run for any number (integer) provided by the user, not only the scenario below.
Example:
Task 1: Please enter a positive number.
Task 2: "Numbers.txt" (file "Numbers.txt" is created with 5 numbers. In the example, 7, 2, 5, 10, and 20 are generated randomly).
Task 3: "Histogram.txt" file showing the number of stars associated with each number from "Numbers.txt".
Grading (not graded):
- Tasks 1-3: Word document (with pseudo code and "Numbers.txt" and "Histogram.txt" files)
- Java source code (comments, naming convention, etc.)
Date: