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

  Determine the percentage of vowels

Create a Java program that asks the user to input a sentence in any language, counts the number of vowels in the sentence, divides it by the total number of characters in the sentence.

  Write an equivalent section of java code.

What is true after the following statements in a C/C++ program have been executed?

  Create four classes that must all interact

You will create four classes that must all interact in some meaningful way. In order to start you will create a class diagram to determine which classes depend on other classes and what those classes are

  Write java program to print strings given at command line

Write a program Average.java which just prints strings that it is given at command line, one per line. If nothing is given at command line, print "No arguments".

  Java classes that are implementations of the rectangle class

Write a Java application that enables the user to specify the length, width and location of two instances of a PlaneRectangle and check whether the first lies completely within the second.

  Create a class named date that stores date values

Create a class named Date that stores date values

  Display all users and their addresses and phone numbers

Display all users and their addresses and phone numbers"); Display all orders in the system and the associated user's firstName, lastName and email");

  Concept of time in javascript

In JavaScript a time is dened as a Date Object. Each date object stores its state as a time value,which is a primitive number that encodes a date.

  Return only the rows where the shipdate

Write a SELECT statement that returns these columns from the Orders table:

  Carl has implemented two programs

Carl picks 20 random names and finds that P1 sorts them faster than P2. "We're using P1!" exclaims Carl. Why are you hesitant to commit?

  Write a java program that will tally and print of medals

For this question, you will write a Java program that will tally and print the counts of gold medals for an international sporting event according to two categorizations: by country, and by event type

  What secret does soraya tell amir

What secret does soraya tell amir and how does amir react to this information

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