Write a program called split in java that reads a text file

Assignment Help JAVA Programming
Reference no: EM131445807

Assignment

Your submission must include:

(a) Source code (b) A report (not to exceed two pages) as an ASCI text document, MS Word document, or a PDF file that contains a description of the ALGORITHM implemented by your program and an analysis of its complexity using Big O notation. It is important that you write a description of the algorithm, not a description of your program! In other words, do not explain your classes and methods. Explain: 1) The sequence of operations that you use to solve the problem, and 2) Why this sequence of operations correctly solves the problem. Pseudo-code is a standard way of explaining algorithms.

Write a program called Split in Java that reads a text file, in.txt, that contains a list of positive integers (duplicates are possible, zero is not considered a positive integer) separated by spaces and/or line breaks. After reading the integers, the program prints out Yes if the set of integers can be split into two subsets with equal sums of elements and with equal numbers of elements. Otherwise (if the list if integers cannot be divided into two subsets satisfying the condition above), the program prints out No. Assume that in.txt contains at least 2 integers.

Examples:

• If in.txt contains 7 7, the program must print out Yes. In this case, the split is {7) and {7}. Both sets are of size of 1, and have the same sum of elements.

• If in.txt contains 5 3 2 4, the program must print out Yes. The split is {2, 5}, {3, 4}. Both sets have the same size, 2, and the same sum, 7.

• If in.txt contains 5 7 5 1 1 3, the program must print out Yes. The split is {1, 5, 5} and {1, 3, 7}.Both sets have three elements and the same sum, 11.

• If in.txt contains 6 5 8 3 4 4, the program must print out Yes. The split is {4, 5, 6} and {3, 4, 8}. Both sets have the same length, 3, and the same sum, 15.

• If in.txt contains 2 6 10 14 4 8 12 16. There are several splits satisfying the requirement: {2, 8, 10, 16} and {4, 6, 12, 14}; {4, 6, 10, 16} and {2, 8, 12, 14}; {4, 8, 10, 14} and {2, 6, 12, 16}; {6, 8, 10, 12} and {2, 4, 14, 16}. Your program does not need to find all of them. It must stop and print Yes after finding the first split satisfying the requirement.

• If in.txt contains 2 13 7 5 16 11, the program must print out No. The set of numbers cannot be divided into two subsets with equal sums and the same number of elements.

• If in.txt contains 7 8 2 4 5, the program must print out No.

• If in.txt contains 8 5 12 24 14 12 4 6, the program must print out No.

Program Specification

The program must solve the problem using a recursive algorithm without modifying the linked list. Although the program requirements specified below might seem contrived an unnecessarily restrictive, their only purpose is to guide you in the right direction and to prevent you from taking a wrong step. The solution, we are looking for is very short and simple.

Your program has to:

(a) Implement a linked list.

You are supposed to implement the linked list from scratch without using language libraries. For example, you are not allowed to use any built-in dynamic data structures, such as ArrayList or LinkedList. Each node of the linked list must include only two elements: an integer and a reference to the next element from the list.

There is no need to provide a full-fledged implementation of linked list. Keep your linked list implementation minimal and implement as much as you need to solve the problem.

(b) Read the integers from the file in.txt and store them into the linked list in the same order in which they appear in the input file. No calculations are allowed at this step; the program must only read the input numbers and store them into the linked list.

(c) Work on the linked list in order to find if the list can be divided into two subsets with equal sums and equal number of elements. All computations must be done in place on the original linked list. In other words, your program can use only one data structure (and only one instance of it), the linked list, some auxiliary scalar variables and reference variables (used to point to different nodes of the list). No additional data structures are allowed, such as a second linked list, an array, string, etc. The only exception is I/O where you can use strings to read in.txt. You can use standard I/O libraries to perform I/O. For example, you can use StringTokenizer or Scanner. This is the only place you can use strings and libraries. No data structures are allowed (with the exception of string used to read in.txt). If you have any doubts whether you can use a particular construct, email me.

(d) Print Yes or No.

(e) The linked list is immutable and your program should not modify it, i.e., it should remain in its original form as it was read from the input file in.txt.

HW2 must be solved by working on the linked list. For example, bypassing the homework restrictions by saving the numbers in a string, array, or any other date structure (with the exception of the linked list) is not allowed and will be penalized. There must be only one instance of the list and it must not be changed, i.e., after you have read the numbers from in.txt and have stored them in the list (in their original order) no further changes of the list are allowed.

Using an integer as a binary mask to store information about subset membership is not allowed. A binary mask is a binary coding of an integer to denote a possible subset configuration. For example, a zero bit in position K in the binary mask means that the K-th integer in the list belongs to a given subset, whereas a zero bit in position K means that the K-th integer in the list does not belong to the subset. By generating all possible binary representations of integers of length N (N is the length of the list) one can generate all possible subset configurations and check if one of them consists of two subsets with equal sums and equal number of elements. Binary masks of this type or variations of them are not allowed.

Pack all your code into one class (one file). Inner classes are allowed.

Try to write simple and short programs. I/O, exception handling, and the linked list implementation could be kept to a minimum. You can also assume that the input is correct and that in.txt is in the same folder as your Java program.

Reference no: EM131445807

Questions Cloud

What is their federal tax liability : Susan and Stan Britton are a married couple who file a joint income tax return, where the tax rates are based on the tax table 3.5. Assume that their taxable income this year was $224,000. What is their federal tax liability? What is their average ta..
How much should he set aside today for the purchase : Stephen plans to purchase a car 4 years from now.The car will cost $64,794 at the time.Assume that Stephen car earn 9.84 percent(compound monthly)on his money. How much should he set aside today for the purchase?
Election of our nations first black president : Many Americans had hoped that the election of our nations' first black President, and with him the appointment of high federal officials, would help the situation, but that does not seem to be the case.
What is their yield to call : Sadik Inc.'s bonds currently sell for $1,334.00 and have a par value of $1000. They pay a $105.00 annual coupon and have a 12-year maturity, but they can be called in 8 years at $1,159.00. What is their yield to call (YTC)?
Write a program called split in java that reads a text file : Write a program called Split in Java that reads a text file, in.txt, that contains a list of positive integers (duplicates are possible, zero is not considered a positive integer) separated by spaces and/or line breaks.
Consider possible trends in society : Review the Discussion Resources, as needed, to look into the future and consider possible trends in society, technology, economics, environmentalism, and politics that could influence your selected firm- PROCTOR AND GAMBLE. Be sure to look beyond ..
Explain a strong objection to your argument : You will continue to build on the arguments that you are presented in your previous two papers. In particular,, you will present a final improved version of your argument for your thesis that you begin for the Week One Assignment and fully address..
Synthesizing theories of personality and motivation : Demonstrate your understanding of personality and motivation and your critical thinking and writing skills by synthesizing theories of personality and motivation as covered in your textbook readings this week.
Determine the best response and find nash equilibrium : Consider the game in which player I chooses a nonnegative number x , and player II chooses a nonnegative number y (x and y are not necessarily integers). The payoffs are as follows.

Reviews

Write a Review

 

JAVA Programming Questions & Answers

  Java application that reads a date in numeric form

Designand write a java application that reads a date in numeric form from a set of three fields and displays it in English within a label. Use appropriate buttons. For Example:

  Design a java application to help the management to

TCS is a full time courier and cargo dispatch agency for corporate companies around the world. It mainly deals with delivering and tracking the package delivered. TCS has its annual budget session during the end of year. With all the information prov..

  Implement the rules and logic for othello

In this project, you will implement the rules and logic for Othello. You are provided with the skeleton code containing the basic methods that you need to complete to launch this game on the java console.

  Write a java program that will read a sequence of names

Write a java program that will read a sequence of names (first name followed by last name, separated by at least one space) from a text file and will 1) remove all duplicate names and 2) write the names (last name followed by a comma, followed by one..

  Calculate the total hours of over lapping meetings

Suppose you have a meeting room which can hold multiple meetings and the smalled duration of meeting can be 30 mins. Calculate the total hours of over lapping meetings.

  Ask the user to enter a positive non-zero integer value.

Write a program which aske the user to Enter a positve non-zero integer value. if the value enterd zero or negative print as error message and end the program; otherwise, use the integer to call a method displayPattern(n) which must display the follo..

  Generate the pseudocode for each of the classes.

Generate an object-oriented design for a system that keeps tracks of your CD and DVD collection.

  Create your own green color for the leaves

Create your own green color for the leaves and display a solid green ellipse filled with your green color whose center is at the beginning of the drag and put a brown rectangle below it as the trunk of the tree.

  Write a general package for reading in arithmetic expression

Write a general package for reading in arithmetic expressions and simplifying them. Write a program for a simple calculating language with two forms of statement.

  Develop a menu driven console java program

Review the text p.933for the use of the printf method and using a format string -  You have completed the console program for collecting statistics for the entry of student marks. We are going to extend this application so the student names and ..

  Design the class line type to store a line

Design the class lineType to store aline. To store a line, you need to store the values of a (coefficient of x), b(coefficient of y), and c. Your class must contain the following operations.

  Accepts a binary number from the user

Write a Java test program that accepts a binary number from the user. You should store the binary number in a String. Your program should then use afor loop to sequence through every character in the String, counting the number of ones, zeros, and..

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