How many points the card is worth

Assignment Help Computer Engineering
Reference no: EM131917235

Assignment

0-1 Solitaire

Suppose we are to play a game in which we have a group of cards with 2 numbers on them. One number is how many points the card is worth, and the other number is how much the card costs. You are given a set allowance you can spend on buying cards. Once you buy a card, you are not allowed to purchase the card again. Your goal is write a program in Java called Game01 that will find the maximum score you can make with the set allowance given. You do not need to necessarily spend all the allowance, but you cannot spend more than the allowance. The program should simply print the maximum score.

Input

The input to your program is a file called in.txt. You can safely assume this file will be in the same location as your program. The format of this file is as follows.

1. The first line contains your given allowance. It is a single integer greater than or equal to 0.

2. The next N lines each contain two numbers representing the points and cost respectively.

a. The points will be random nonzero positive integer values.
b. The costs will be random nonzero positive integer values.
c. The number of cards, N, is random but there will at least be 1 card.

3. There may be duplicate cards with either the same point value and same cost or same point value and different costs.

Output

The output of your program should be a single integer that is the maximum score that can be made by purchasing cards.

Examples

The following examples are not representative of the format in.txt will have. For the format, refer to the "Input" section.

Allowance 5

[6, 2], [8, 2], [4, 2], [7, 1], [7, 1], [3, 2] → The maximum score is 22. The cards bought are [8, 2], [7, 1], [7, 1] where the final cost is 4.

Allowance 5

[10, 1], [8, 10], [10, 3], [7, 2], [3, 2] → The maximum score is 20. The cards bought are [10, 1], [10, 3] where the final cost is 4.

Allowance 15

[5, 12], [10, 8], [4, 6], [5, 8] → The maximum score is 14. The cards bought are [10, 8] and [4, 6] where the final cost is 14.

Allowance 15

[5, 4], [1, 4], [2, 4], [4, 2], [2, 5], [4, 1], [2, 2] → The maximum score is 17. The cards chosen were [5, 4], [2, 4], [4, 2], [4, 1], [2, 2]. The final cost is 13.

Allowance 5

[77, 18], [68, 11], [63, 12] → The maximum score is 0. There are no cards that can be bought so the final score is 0.

Allowance 100

[96, 17], [85, 15], [87, 16], [74, 20], [62, 19], [55, 15], [65, 16], [78, 16], [97, 19], [83, 18] → The maximum score is 508. The cards bought are [96, 17], [85, 15], [87, 16], [65, 16], [78, 16], [97, 19] with the final cost of 99.

The examples presented are not the only tests that may be used to check your algorithm is correct so be sure to test with many different values for allowance, points, and costs.

Criteria

To receive maximum points for this assignment you must follow the guidelines presented here.

1. You must implement and utilize a singly linked list. The linked list must be written from scratch by you. Only implement the necessary methods that will help you solve the problem. Try to keep your linked list implementation minimal.

a. You may not use the built-in list implementations in the Java library. This includes Linked List and Array List.

b. Each node of the linked list must include only three elements: two integer types and a reference to the next element of the list. The nodes represent the cards.

c. You may not have more than one instance of a linked list.

2. Read the cards data from a file called in.txt as specified in the input section of this document. You can assume this file is in the same location as your program.

a. No calculations are permitted while reading in the data from in.txt.

b. Once the data is read into your linked list, you may not manipulate the data or the list. For example, you may not sort, shuffle, remove, or add to the list. Once the cards have been read in, the list must remain the same throughout the life of the program.

c. Your program may not modify the file at all. It should perform read-only operations.

3. No additional data structures are allowed. This includes arrays, strings, trees, etc. All computations must be done in place in the original linked list (section 2b). Your program may use auxiliary scalar variables and reference variables (used to point to nodes of the list).

a. There is only one exception to the rule and that is when you are reading in the data you may use strings. This is also the only time you may use the standard library as well. For example, you can use StringTokenizer and/or the Scanner library.

4. Bit masking is not allowed and is not a solution. Use of an array of Booleans or integers is also disallowed according to guideline 3.

5. All code should be placed in one .java file and must be able to be compiled and ran from that .java file. Inner classes are allowed. Again, try to write short and simple programs. I/O, exception handling, and the linked list implementation should be kept to a minimum.

Assignment 2 must be solved by following these guidelines. Bypassing any of these, such as saving numbers in string or using an array to keep track of additional data will be penalized. If you have any questions about what can and cannot be used, you may email me.

Your Analysis

The final part to this assignment is your analysis of the problem and your algorithm and the complexity of the problem. The report should not exceed two pages and should be in the format of an ASCII text document, MS Word document, or PDF.

NOTE: It is important that you write a description of the algorithm and not a description of your program!

You should explain

• The sequence of operations that you use to solve the problem.
• Why this sequence of operations correctly solves the problem.

o Pseudocode is a standard way to explain an algorithm.

• The complexity. (The BigO of the problem).

What you need to turn in

Once you have completed the assignment and are ready to submit you must zip all your files into a single zip archive. The extension must be .zip. The name of the .zip file must be your netID so if your netID were broge2 then the file must be named broge2.zip.

The files that must be in the zip are your .java file that contains all your code and must be compileable and runnable and must solve the problem laid out in this document. It must also contain the document file that describes your algorithm and the complexity. The name of this file is up to you.

Attachment:- Text-File.rar

Reference no: EM131917235

Questions Cloud

Wittig synthesis of styrene : Draw the two different ylides that could be used in the Wittig synthesis of styrene.
What are classical and discounted payback periods : What are the classical and discounted payback periods? What are the four accounting rate of returns (utilizing cash flows)?
Design a nested menus interface for a check-in and checkout : Design a nested menus interface for a check-in and checkout hotel reservation system that can be used internationally. Use numbers to select a menu item.
What is an agency relationship : What is an agency relationship? When you first begin operations, assuming you are the only employee and only your money is invested in the business.
How many points the card is worth : One number is how many points the card is worth, and the other number is how much the card costs. You are given a set allowance you can spend on buying cards.
Automatic stabilizer in the economy : Regarding the economy, what are the terms expand and contract generally used to describe? Which of the following is an automatic stabilizer in the economy?
Evaluation of the articles effectiveness and credibility : MGMT: Critical Thinking and Managerial Decision Making - Assessment: Practical and Written - Based upon the article is there a gap in the literature or some
What steps were taken to overcome the cannibalization : In your own words, identify two corporations that have dealt with cannibalization and what steps were taken to overcome the cannibalization.
Retained earnings versus new common stock : Calculate the cost of retained earnings and the cost of new common stock using the? constant-growth valuation model.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Explain the modified scorecard approach

express the Value Based Management approach of demonstrating business value. Explain the Modified scorecard approach to measuring IT value. What is the benefit of this approach? Describe the concept of  balanced score card.

  Describe algorithm for computing number of descendents

Describe, in pseudo-code, algorithm for computing number of descendents of each node of binary tree. The algorithm should be based on Euler tour tour traversal.

  Describe the solution that you built

Describe the solution that you built and how it was used in your analysis (i.e. did you create a "what-if" scenario, use Solver or Scenario Manager, etc.).

  Which design strategy would you recommend for construction

The agency wants to keep a database of its own property listings and also wants to have access to the citywide multiple listings service used by all real estate agents. Which design strategy would you recommend for the construction of this system? ..

  How to modify the product program to use a gui

create the product Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that..

  Computing the unit price of items

The Manager of the Supermarket would like to be able to compute the unit price of items sold there. To do this the program must input the name and the price of item and its weight in pounds and ounces.

  Create a logical data model that represents the file

You have been given a file that contains fields relating to CD information. Using the steps of normalization, create a logical data model that represents this file in third normal form.

  What is the difference between offensive and defensive

What is the difference between offensive and defensive counterintelligence, and the most effective measures used to practice defensive

  Compare three input devices and three output devices

Compare three input devices and three output devices. There are several types of print technologies available for computer technicians.

  Describe a nonrecursive algorithm for enumerating

Describe a nonrecursive algorithm for enumerating all permutations of the numbers {1,2,...,n}.

  Explain using a computer program and programming a computer

Suppose you have a random sequence of colored marbles. Explain the difference between using a computer program and programming a computer.

  Compare stateless firewall rules with an acl

Compare stateless firewall rules with an ACL. Explain why using proxy servers helps with securing web traffic. Describe site-to-site and client-to-site VPN.

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