JAVA数据结构multiply-linked data structures程序代写(服务编号:java00088)

The program

The purpose of this assignment is to provide some exercise in using multiply-linked data structures.

Your program will be a number grid. It will provide a grid with ten rows and six columns. A cell in the grid can hold and display either a number (a double) or a string. Operations will be provided which display the grid, assign values to the cells, do arithmetic on cells, do arithmetic on rows and columns, fill cells with values, insert, delete, and move rows and columns. The default value for all cells is an empty string. The program will present a menu of operations to perform. When input is taken from the user for a cell value any input beginning with a double quote mark (") is treated as a string. The quote mark is not included in the string. Any other input is assumed to be a number and is accepted as a double. Data structures

Each cell in the grid will be represented by a Node (a class) with a Value field and two pointer (i.e. reference) fields, right and down. Theright pointers will be used to link the nodes into rows and the down pointers will link the nodes into columns. Each row will be linked as a circle (the right field of the final node in each row will point to the first node in the row) as will each column (the down pointer of the bottom node pointing to the top node of the column).

Value is represented as a class with three fields: a double field, dval, to hold numeric values, a String field, sval, for character strings, and a tag field which indicates whether the Value is currently a number or string (or is invalid). Arithmetic (+, -, *, and /) can be performed on Values.

The grid itself will be an instance of a Grid class. This class will have integer fields for the number of rows and number of columns. Use the value 10 for field width when displaying cells. Grid will have a head field which points to the first node of the grid (at row 0, column 0). A constructor and a number of public methods for the grid operations will be written.

Internals

After the (number of rows) × (number of columns) nodes have been created and linked together by the constructor for Grid all access to nodes will be done through pointer operations beginning at head.

Values

The Value class represents the values that can be stored in the nodes. A value can be either a double or a string. A separate data field is provided for each so it is possible for a "Value" to contain both a double and a string. The tag field indicates which of these data fields holds the "real value" of the Value. A Value can also have an "INVALID" tag. This tag value is only used for (some) intermediate results in arithmetic and a Value with an INVALID tag is never stored in a node. Values are constructed with tag STRING, dval 0, and svalnull.

Arithmetic can be done on Values with the operators plusminusstar, and slash. Each of these will be implemented as a method of the Value class taking a Value as parameter and returning Value. The operators will first check to see if the tags of both operands are DBL. If not no arithmetic is performed and the tag of the resulting Value is set to INVALID. Otherwise the sum, product, etc., is computed and the result stored in the dval field of the resulting Value. The tag is set to DBL.

You will write a toString method for Value. Useful methods: String.format("%10.4f", x) will return a String representation of the double x to 4 decimal places in a field width of 10 charactes; String.format("%10s", str) will return a String containing the (sub-)String str in a field of 10 characters.

Notice that you do not know whether the input will be a double or a string until after it has been entered. To resolve this problem accept the input as a String and check the first character. If it is a double quote mark (") it is a string and copy it (after allocating memory) withoutthe quote mark to the sval field. Otherwise the input is intended as a double. In this case convert it to a double with Double.parseDouble and store the result in the dval field.

The Grid class

The Grid class has methods to print the grid, to do arithmetic on the cells, to insert and delete rows and columns, and to assign values to the cells.

The display method will display the grid. Each cell will be displayed in a field of 10 characters and doubles will be displayed with 4 decimal places. The row and column numbers will be displayed.

Grid arithmetic

Arithmetic can be done on individual cells with addNodessubNodesmulNodes, and divNodes methods. Other methods perform arithmetic on entire rows (addRows, etc.) or columns (addCols, etc.) at a time. In all cases once you have located the nodes to be operated on you can just "add," etc., the Values and assign Values without accessing the Value‘s data fields or checking tags by simply using the arithmetic methods from Value.

Inserting and deleting nodes

Entire rows and columns can be inserted into the grid using insertRow and insertCol. Rows and columns can be deleted using deleteRow and deleteCol. These methods work through much fussing with pointers and require a certain amount of care to code.

Assigning Values to cells

Two methods assign values to cells: number and fillnumber requires the row and column numbers of two grid cells. These define a rectangular "subgrid" having these two grid cells as corners. number will assign the numbers 0, 1, 2, etc. (as doubles) to these cells. fill is similar but it puts the same Value (passed as a parameter) in the node representing each cell.

Notice that fill can be used to assign a value to a single cell.

Validation

For all methods the parameter values must be validated. Each row and column number must be in the correct range (between 0 and Grid.rows-1 and between 0 and Grid.cols-1 respectively). If two row/column pairs are used to define a subgrid (as with number and fill) the first pair cannot follow the second (but they can be the same). The delRow and delCol methods must not reduce the grid to an empty grid (there must always be at least one row and one column in the grid). Methods which do division must check for zero divisors. If a zero divisor is found and error message is displayed, the division is not performed and the resulting Value will have tag INVALID. Any other validations needed for the methods to make sense must be done.

The driver

To run your grid you will write a program which will create a grid (using the default size of ten rows and six columns). The program will run in a loop which displays a menu offering all of the choices seen in the sample run shown above, accepts user input, and then performs the requested operation by calling the appropriate method.

A final note

Test your work thoroughly and in small pieces as you proceed. A small problem in Value or the constructor for Grid, for example, which might not be apparent under overly simple testing can cause major, and difficult to trace, problems later on.

Note that much code is used repeatedly in this program. Simplify your program by factoring out this common code where appropriate. For example, adding a few private methods to class Grid to handle common operations in moving around the grid can clean up your code considerably.

To hand in

You will hand in a hard copy of your source files and of a sample terminal session. For the terminal session you will run your program with sample operations which will be provided to you. There will be no electronic submission.

时间: 2024-11-08 11:03:21

JAVA数据结构multiply-linked data structures程序代写(服务编号:java00088)的相关文章

The Assignment6 class extends JApplet程序代写(服务编号:java00089)

Skills to be Applied: Swing/AWT, Vector (very similar to ArrayList class) Classes may be needed:JApplet, JButton, JTextField, JTextArea, JLabel, Container, JPanel, JTabbedPane, JList, JRadioButton, ButtonGroup, and ActionListener. You may use other c

java图形图像SVG转PPM程序代写 qq:928900200

Background Many image file formats encode image data as a 2-D matrix or raster of pixel colors. The amount of available color information is fixed by the image's width and height of its resolution. If the resolution is too small, you will have proble

基于JAVA WEB技术旅游服务网站系统设计与实现网上程序代写

基于JAVA WEB技术旅游服务网站系统设计与实现网上程序代写 专业程序代写服务(QQ:928900200) 随着社会的进步.服务行业的服务水平不断发展与提高,宾馆.酒店.旅游等服务行业的信息量和工作量日益变大,而传统的人工管理方式已经远远不能满足现在旅游的服务方式.传统的旅游方式经分析其有诸多的缺陷,存在数据维护效率低下,不易保管,容易丢失和出错.同时查询也不方便,劳动力成本过高导致的旅游资源信息不方便,也在一定程度上导致了对各种信息反应缓慢,容易丧失商机.为了弥补上述缺陷,便于开展旅游预订工

无锁数据结构(Lock-Free Data Structures)

原文:无锁数据结构(Lock-Free Data Structures) 一个星期前,我写了关于SQL Server里闩锁(Latches)和自旋锁(Spinlocks)的文章.2个同步原语(synchronization primitives)是用来保护SQL Server里的共享数据结构,例如缓存池里的页(通过闩锁(Latches)),锁管理器哈希表里的锁(通过自旋锁(Spinlock)).接下里你会看到越来越多的全新同步原语(synchronization primitives),即所谓的

java代写,java程序代写,代写java,java编程代写

java代写,java程序代写,代写java,java编程代写 我们5人Team都是来自于国内一线互联网公司的高级工程师,毕业于顶尖CS院校,已经接编程代写达2年时间,阵容详细介绍见此 学生来自于美.澳.加.英.中国含中国香港.中国澳门.中国台湾,接单数量近1000单 这里有我们的接单截图记录,可以看到我们的高效.诚信.靠谱:代写成交截图 联系方式 加之前务必了解价格详情:价格详情 有详细价格范围 防止浪费时间 精力有限,仅接学生作业,不接社会需求!不接社会需求! 不接[深度学习].不接[图像处

SQL 语句代编代写、DATA MANAGEMENT SYSTEMS代写代做

SQL 语句代编代写.DATA MANAGEMENT SYSTEMS代写代做DATA MANAGEMENT SYSTEMS DESIGN PROJECTPurpose of this projectAnalyze, design, implement, and document a database system application. You will use the methodology for database development learned in class. The sys

board game作业代写、代写board game程序、C程序代写

board game作业代写.代写board game程序.C程序代写Watch Your Back! is a fast-paced combat board game. You control a team of ruthless roguesengaged in a fight to the death against your enemies. Within the confines of a checkerboardthere is no rulebook and no referee

c++程序代写(qq:928900200)

1. Both main memory and secondary storage are types of memory. Describe the difference between the two.2. What is the difference between system software and application software?3. Why must programs written in a high-level language be translated into

C语言程序代写(qq:928900200)

1cs3157 – Advanced ProgrammingSummer 2014, Project 1, 150 pointsJune 17, 2014Follow these step-by-step instructions. This homework must be submitted electronically bySunday night July 6th, 11pm. Please start early, so we can help if you get stuck.In