Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will write a Java program to do the followings: 1. Read a sequence of values from a le into an array

In this assignment, you will write a Java program to do the followings:
1. Read a sequence of values from a le into an array list.
2. Print out the original list values.
3. Convert the original list values into bar values within the range of [0, 30], and save them in a new array list. To do so, you must nd the maximum value in the list rst, say max. The remaining values should be computed based on the the formula:value30=max, where value is the original value.
4. Print out the bar values.
5. Print out the bar charts with the bar values.
6. Sort the bar values usingCollections.sort().
7. Print out the sorted bar chart.Three sample input files are given to you. A sample output corresponding toinput1.txt is shown in Figure.
Requirements of the program:
1. You should implement methods for this program. If you implement everything withinmain(), you will lose 30 points.
3. Your program should prompt user to enter input le name. While only three input files are given, your program should accept other input file.
4. Your program output should be neat, including labeling and spaces .
5. Your program should have good style (indentation, whitespace, comments, verticalalignment, ...).
Input1.txt
20 30 40 50 25 90 65
input2.txt
200 300 400 500 250 900 650
input3.txt
2000 3000 4000 5000 2500 9000 6500
import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
public class SortedBarChart
{
/**
* Read a sequence of positive integers from a given input file,
* and construct an array list out of them.
*
* @param fileName: the input file name
* @return an array list of values
*/
public static ArrayList readValues(String fileName) throws FileNotFoundException
{
ArrayList list = new ArrayList();
//....
return list;
}
/**
* Return the largest element in the array list.
*
* @param list: the input list
* @return the largest element in list
*/
public static int findMax(ArrayList list)
{
int max=0;
//...
return max;
}
/**
* Prints a chart of asterisks with list value, based on the input list.
*
* @param list: the input list
*/
public static void printBarChart(ArrayList list)
{
//...
}
/**
* Prints the list value in one line
*
* @param list the input list
*/
public static void printArrayValues(ArrayList list)
{
//...
}
/**
* Convert the list valeus into corresponding bar values proportion to the largest element in the list.
* Truncate the fraction part if the resulting bar value is not a whole number
*
* @param list the input list
*/
public static ArrayList convertBarValues(ArrayList list)
{
ArrayList newList = new ArrayList();
//...
return newList;
}
public static void main(String[] args)
{
//...
}
}
image text in transcribed
image text in transcribed
Bluet Terminal Window . Prog 1_ArrayApp-Bar." - Options Enter your input file name: input1.txt Original Values 20 30 40 50 25 90 65 Bar Values: 61 13 16 8 30 21 Bar Visualization: 6) (10) (13) R (16) 8) A (3) AR (21) Sorted Bar Values: 6 8 10 13 16 21 30 Sorted Bar Visualization: 6) (10) (13) (16) (21) (30) e Email - Save

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

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions