Write a complete java program that draws a scatterplot

Assignment Help JAVA Programming
Reference no: EM131244840

Part A: Shopping ArrayList

A classic application program is the shopping list: a way of keeping track of which groceries or other items need to be bought, and which of them have already been purchased. Your answer to this question will implement such a shopping list, and simulate a user's changes to the list with data read in from a text file.

First, you will need a class to represent items in the list. Objects of this class will contain two instance variables, a String name of the desired item, and an int quantity that needs to be purchased.

Secondly, you will need two ArrayLists in your program. The first list will keep track of items that still need to be bought (call this the shopping list), and the quantity needed. The second will keep track of the items purchased, and the quantity that has been purchased (call this the purchase list).

The data file used as input to the program will consist of lines containing one of three commands. The first of these is add, which is followed by a quantity and an item name, separated by commas. This will add to the shopping list; if an item with that name already exists, increase the quantity desired by the given number. Otherwise, add a new item to the list with that name and quantity.

The second command is buy, which is also followed by a quantity and an item name. This will add to the purchase list in a similar fashion. Also, if an item with that name is already in the shopping list, reduce the quantity desired by that number. If the quantity of that item reaches zero (or less), remove it from the shopping list. Finally, the list command should print out both lists, showing both the quantity and the item name, one item per line.

Part B: Scatterplot

Write a complete Java program that draws a scatterplot by reading in points of data from a file and displaying them. The input data file consists of a pair of integers representing a point on each line of the file; the first integer is the x coordinate, and the second is the y coordinate of the point. It should then plot a least squares regression line on top of the points.

You may assume that all valid points have x-coordinates in the range [0, 40] and y-coordinates in the range [1, 20]. The least-squares line is calculated using the following formula:

Your program should be able to deal with errors in the data file (by catching NumberFormatException when converting text to integers). Ignore lines containing invalid data or points with coordinates out of range, but do not stop reading the file.

Use a two-dimensional array of characters to store the plot.

Your program should print two scatterplots, using the input files a3plot1.txt and a3plot2.txt.

Attachment:- Assignment.rar

Verified Expert

The assignment had 2 programs in it. Shopping List This program reads a file and processes it accordingly.An add entry adds the item to shopping list.A buy entry adds item to purchase list and deletes from shopping list if enough quantity is bought.List displays both the lists. ScatterPlot Reads a file and draws a linear square regression line.Graph is stored as a two dimentional array of characters.

Reference no: EM131244840

Questions Cloud

Use cournot model to derive an equilibrum industry structure : We can use the Cournot model to derive an equilibrum industry structure. For this purpose, we will define an equilibrum as that structure in which no firm has an incentive to leave or enter the industry. If a firm leaves the industry. it enters an el..
Find the code word to represent the 10-bit information : Assuming we are using the Hamming algorithm presented in this chapter to design ourerror-correcting code, find the code word to represent the 10-bit information word:1001100110.
How new technology might be applied in the work environment : Identify an example of new technology. Explain how it might be applied in the work environment. Explain potential benefits of adding this new technology. Explain potential drawbacks of adding this new technology.
Calculate the expected return to each project : Calculate the Expected Return to each project; Rank these projects in terms of attractiveness from a risk-averse perspective; Assess how your answers change if the likelihood of these outcomes changes such that there is an 70% chance of an economic b..
Write a complete java program that draws a scatterplot : Write a complete Java program that draws a scatterplot by reading in points of data from a file and displaying them. The input data file consists of a pair of integers representing a point on each line of the file; the first integer is the x coord..
The purchase of this piece of equipment : It is estimated that a certain piece of equipment can save $6,000 per year in labor and material cost. The equipment has an expected life of five years and no salvage value. If the company must earn a 15% annual return on such investments, how much c..
Identify three aspects of portfolio management : Speculate on why corporate culture plays a critical role in developing a more agile product development approach. Provide one (1) real-world example of the role that corporate culture plays in agile product development to support your response.
How are constraints on time and money related : Over the last several years, a number of municipalities in California have adopted restrictions on the bags that grocers are allowed to give to customers. The nature of the restrictions varies by municipality, but generally a customer must either pro..
Find the residence time distribution : Find the residence time distribution, that is, the effluent concentration of tracer

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a program that allows a user to enter a line of text

Write a program that allows a user to enter a line of text, counts number of words and number of vowels in the sentence, and gives the average number of vowels per word in the message

  Create a program in java that displays hello world

Create a program in Java that displays "Hello world!", No Design Section is required for this assignment, Copy and Paste your code into the Source Programs section and a screen shot of the results in the Output section.

  Tasks for an array of integers

Write array methods that carry out the subsequent tasks for an array of integers by completing the ArrayMethods class below. Test each method.

  Create java servlets

Create a new JSON "view" (e.g., a JSP page that only displays the JSON representation of the data)

  Write the entry or record into a sequential file

Develop a Java based GUI application(using swing) that allows the user to enter Charity/Fund information: Write the entry/record into a sequential file

  The data file being used contains records

The data file being used contains records with an employee's name, the number of hours they worked, and their hourly pay rate. Write a program to read the records of information and output (to the Output window or a dialog box) the employee's name..

  Java program use breadth-first search closest broadcast

Write the java program which will use breadth-first search (which you implement as part of your program) to determine the closest broadcast vertex for each vertex in graph.

  Write an application in which the user can enter a date

Write an application in which the user can enter a date using digits and slashes (for example, " 6/24/2012 " ), and receive output that displays the date with the month shown as a word

  Write program that uses a class named rectangle

Write program that uses a class named Rectangle. The class has floating point attributes length and width. it has member functions that calculate the perimeter and area of the rectangle. It also has set and get functions for both length and width.

  Write java code to read integers from an input file

write java code to read integers from an input file and write only the odd numbers to an output file. the two file names will be provided on the command line as the input file followed by the output file.

  Program-measure running time of different sorting algorithms

Write a JAVA program that measures the running time of different sorting algorithms such as heap sort, in-place quick sort and merge sort for 10,000 randomly generated integer numbers.

  What is an advantage of executing a process in background

What is an advantage of executing a process in background? How do you execute one program from within another?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd