Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Assignment

Java program that reads text file, that contains a list of positive integers....

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.

The assignment 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.

Java, Programming

  • Category:- Java
  • Reference No.:- M92258508
  • Price:- $110

Priced at Now at $110, Verified Solution

Have any Question?


Related Questions in Java

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As