Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use java netbeans please 1) Lab 7a a) Create a txt file with following data and name the in file Lab7a.txt 5 4 8 2

Use java netbeans please
1) Lab 7a
a) Create a txt file with following data and name the in file Lab7a.txt
5
4
8
2
7
3
15
52
60
b) Write a JAVA Program to implement array.
The program should read integer values from file and store them in an array named iArr.
Define the size of array as 10.
Display elements of array as shown in sample output.
You also need to find out the largest number, smallest number, sum of the numbers and average of them.
Display them as shown in sample output.
NOTE:
Your class name should be Lab7.
Follow good programming practices such as comments, indentation etc.
// Lab 7a
// CS 1113
// Name:
import java.util.Scanner;
public class Lab7a
{
public static void main(String[] args)
{
// Define your Scanner object
[Add Code Here]
// Define size of array, ARR_SIZE as 10
[Add Code Here]
// Declare your array, iArr, of type int with size ARR_SIZE
[Add Code Here]
// Define a variable, size, to count the number of numbers left and initialize it with 0
[Add Code Here]
// Read the value for your iArr until there are numbers left in file to read and
// there is space in your array to store new value using while loop
// Refer to class note if you do not know how to do this
[Add Code Here]
{
// Read value for file and store it in iArr[size]
[Add Code Here]
//Increase the size
[Add Code Here]
} // End of while loop
// Display the elements of array
// Look at class note for how to display elements of an array
[Add Code Here]
// Define variable max, min, sum and initialize all of them with iArr[0]
[Add Code Here]
// Start your loop for i = 1 to size
[Add Code Here]
{
// compare iArr[i] element with max and if iArr[i] is greater than max,
// then assign value of iArr[i] to max
[Add Code Here]
// compare iArr[i] element with min and if iArr[i] is smaller than min,
// then assign value of iArr[i] to min
[Add Code Here]
// Add value of iArr[i] to sum
[Add Code Here]
} // End of for loop
// Declare a variable, average, and calculate the average of all array elements.
[Add Code Here]
// Display necessary output as shown in sample output.
[Add Code Here]
} // end of main method
} // end of Lab7a
c) A sample run with the given input can be seen below.
java Lab7a < Lab7a.txt > Lab7a_out.txt
Elements of my array are:
iArr[0] = 5
iArr[1] = 4
iArr[2] = 8
iArr[3] = 2
iArr[4] = 7
iArr[5] = 3
iArr[6] = 15
iArr[7] = 52
iArr[8] = 60
The largest number is 60.
The smallest number is 2.
The sum of numbers is 156.
The average of numbers is 17.33.
d) Edit your Lab7a.txt file to have more numbers than the array
will allow, lets say, Lab7a_overflow.txt as
5
4
8
2
7
3
15
52
60
55
1
15
18
21
e) Run the program with Lab7a_overflow.txt as input file and store your result in a new output file Lab7a_overflow_out.txt.
f) Turn in your input files (Lab7a.txt, Lab7a_overflow.txt), your output files (Lab7a_out.txt, Lab7a_overflow.txt) and Lab7a.java file.
======================================================================================================================================
2) Lab 7b
a) Create a txt file with following data and name the in file Lab7a.txt
12.5
6.2
-5.3
0.0
2.39
0.0
16.32
18.35
0.0
-9.35
0.0
15.23
b) Write a JAVA Program to implement array.
The program should read double values from file and store them in an array named iArr.
Define the ARR_SIZE of array as 50.
Display elements of array as shown in sample output.
You need to display the original array elements, reversed array elements and total numbers of 0 (if any) in original or reverse array.
Display them as shown in sample output.
NOTE:
Your class name should be Lab7.
Follow good programming practices such as comments, indentation etc.
// Lab 7b
// CS 1113
// Name:
import java.util.Scanner;
public class Lab7a
{
public static void main(String[] args)
{
// Define your Scanner object
[Add Code Here]
// Define size of array, ARR_SIZE as 50
[Add Code Here]
// Define your array, arrayOne, of type double with size ARR_SIZE
[Add Code Here]
// Define a variable, count, to count the number of numbers left and initialize it with 0
[Add Code Here]
// Read the value for your arrayOne until there are numbers left in file to read and
// there is space in your array to store new value using while loop
// Refer to class note if you do not know how to do this
[Add Code Here]
{
// Read value for file and store it in arrayOne[count]
[Add Code Here]
//Increase the size
[Add Code Here]
} // End of while loop
// Display the elements of array
// Look at class note for how to display elements of an array
[Add Code Here]
// Define your array, arrayTwo, of type double with size count
[Add Code Here]
//Define a variable, countZero to count the number of Zeros and initialize it with 0
[Add Code Here]
// Reverse your array using for loop starting with 0 to count - 1
[Add Code Here]
{
// arrayTwo[i] has to be the last element of arrayOne[count - 1],
// arrayTwo[i + 1] has to be the last element of arrayOne[count -1 - 1],
// arrayTwo[i + 2] has to be the last element of arrayOne[count -1 - 2]
// and so on......
[Add Code Here]
// Check if arrayOne[i] is 0.0. If yes, increase countZero by 1
} // End of for loop
// Display the elements of reversed array
[Add Code Here]
// Display the number of Zeros
[Add Code Here]
} // end of main method
} // end of Lab7b
c) A sample run with the given input can be seen below.
java Lab7b < Lab7b.txt > Lab7b_out.txt
Original array is :
12.5 6.2 -5.3 0.0 2.39 0.0 16.32 18.35 0.0 -9.35 0.0 15.23
Reversed array is :
15.23 0.0 -9.35 0.0 18.35 16.32 0.0 2.39 0.0 -5.3 6.2 12.5
Number of ZEROS in array is : 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions