L10
Due by the end of Tuesday, 23 March 2021
SUBMIT
/
CHECK
Today's Activities
- Programming Activity 1
-
Download the program
SumUsersFile.java
into your L10/src folder.
Download the data files
3Doubles.txt
and
100Doubles.txt
into your L10 project folder.
Note that the data files don't go into the src folder.
They go into the folder
that the src folder is in
(L10, or whatever you called your project).
Revise SumUsersFile
so that it reads and sums doubles
instead of integers.
Test it using the data files provided.
- Programming Activity 2
-
Download the program
WeeklyTemps.java
(into your L10/src folder).
This program is the one
that reads seven temperatures into an array,
calculates their average,
then prints out the temperatures
and how far off the average they are.
I want you to revise it
so that it reads the temperatures from a file,
where the user provides the name of the file.
(The output still goes to the screen.)
Test your program using the 100Doubles.txt data file
you downloaded for the previous activity.
(Don't worry about the extra numbers.
The program reads seven temperatures
and ignores the rest.)
To think about:
What happens if you use 3Doubles.txt as the input file?
Why does that happen?
- Programming Activity 3
-
Create a program called CountingBy.
It asks the user
for a number to count by and a number to count to.
Then it asks
for the name of a file.
Finally,
it prints the numbers into the named file.
For example,
What shall I count by? 5
What shall I count to? 100
What file shall I save the numbers in? byFives.txt
The file byFives.txt has been created.
And here is what would be in the file byFives.txt.
Note:
-
The numbers start at the number to count by.
-
The numbers end at the number to count to.
-
The number goes up each time
by the number to count by.
-
You know where to start,
where to end,
and how much to go up by each time,
so you can use a for loop.
-
If the number to count to
is not a multiple of the number to count by,
then the numbers will end before it.
For example,
counting by 7s to 50 gives 7 14 21 28 35 42 49.
But you don't have to worry about that!
Just make sure your program doesn't print any numbers
bigger than the number to count to,
and you'll be fine.
Submit this/these files:
- SumUsersFile.java
- WeeklyTemps.java
- CountingBy.java
You will be graded on the following:
- SumUsersFile compiles; variables revised to be double instead of int
- . . . checks for and reads doubles instead of ints
- WeeklyTemps compiles; revised to prompt for and read file name from user
- . . . opens file for input
- . . . reads correct number of temperatures from file, without prompting
- . . . closes input file immediately after the temperatures have been read
- . . . produces required output as before
- CountingBy compiles; prompts for and reads range of loop
- . . . prompts for and reads output file name
- . . . opens file for output
- . . . produces correct(ish) output to that file
- . . . closes that file after the output has been sent to it
SUBMIT
/
CHECK