In this assignment, you will build a program using techniques from previous CSS courses that counts...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this assignment, you will build a program using techniques from previous CSS courses that counts unique fractions. No new constructs from our readings are expected, and as such, you can complete this program with just a handful of lines (12-25) of code in just one main function. (But do NOT feel that your code needs to be that short!) Note that the use of methods will improve your design and improve your grade. You will need to use loops, ifs, comments, etc., (in other words, structured programming) to complete this assignment and achieve the outcomes listed below. Included below is a sample execution of your program as well as a list of outcomes your program is to implement; notice reduction of fractions is optional in this version of the assignment. Do NOT build any classes (other than your driver, obviously). Do NOT use any fancy class structures like ArrayList, Set, Hashmap etc. Introduction Your project is to read in a series of fractions from a text file, which will have each line formatted as follows: "A/B". A sample text file is listed below, and the purpose of your program is to read in each fraction and count the number of occurrences for the current fraction. When all the input is consumed (or as the input is consumed), your program will print out its list of unique fraction and their corresponding count - see the output below (and you may assume no blank lines or misleading characters; see the text file link on the website for one of the actual inputs I'll use when testing your submission). Sample Input File fractions.txt ↓ Sample Text Input 6/3 7/3 6/3 12/6 Sample Console Output 6/3 has a count of 3 7/3 has a count of 1 NOTE: it is also fine (though not required) if your program simplifies the fractions so that the output is: 2/1 has a count of 3 7/3 has a count of 1 ---But either way, 6/3 and 12/6 count as the same fraction, so you do need some mechanism for determining if two fractions that look different are actually the same. The only optional part of the assignment is how you display them in the end. Questions Answer the following questions using multi-line comments in your code, at the top. (5%) 1. Can you complete this without using arrays? What is the least number of variables you can use to solve this problem? 2. Can you use just one array to solve this? What would the data type be of that array? 3. What does it mean to make a class so another class is inside (or part of) the first class, so that it is composed of other data types? What does "composition" mean in that case? How is it done? 4. What are some solutions to the reduction problem other than Euclid's GCD algorithm? Notes & Hints • Be sure to put code that gets lengthy into its own method! • This assignment is particularly guiding in the outcomes section; expect future assignments to test your ability to build your own programming contract for the problem at hand. • Test your code as you add features (either methods or variables) incrementally, making sure your small change works as you envisioned it to. • Try to keep in mind basic "structured programming" principles such as modular design (ie, decompose complex tasks into individual methods), good variable & methods names (self-documenting code), and comments. • Consider reading one line at a time (with scanner.nextLine()), and using the split function (defined in class String) to give you an array with two elements in it (the numerator and denominator, respectively) • Don't wait till the last minute to get help from the instructor, the TA, or our lab tutors! • The file you turn in should be called fractionsv1.java In this assignment, you will build a program using techniques from previous CSS courses that counts unique fractions. No new constructs from our readings are expected, and as such, you can complete this program with just a handful of lines (12-25) of code in just one main function. (But do NOT feel that your code needs to be that short!) Note that the use of methods will improve your design and improve your grade. You will need to use loops, ifs, comments, etc., (in other words, structured programming) to complete this assignment and achieve the outcomes listed below. Included below is a sample execution of your program as well as a list of outcomes your program is to implement; notice reduction of fractions is optional in this version of the assignment. Do NOT build any classes (other than your driver, obviously). Do NOT use any fancy class structures like ArrayList, Set, Hashmap etc. Introduction Your project is to read in a series of fractions from a text file, which will have each line formatted as follows: "A/B". A sample text file is listed below, and the purpose of your program is to read in each fraction and count the number of occurrences for the current fraction. When all the input is consumed (or as the input is consumed), your program will print out its list of unique fraction and their corresponding count - see the output below (and you may assume no blank lines or misleading characters; see the text file link on the website for one of the actual inputs I'll use when testing your submission). Sample Input File fractions.txt ↓ Sample Text Input 6/3 7/3 6/3 12/6 Sample Console Output 6/3 has a count of 3 7/3 has a count of 1 NOTE: it is also fine (though not required) if your program simplifies the fractions so that the output is: 2/1 has a count of 3 7/3 has a count of 1 ---But either way, 6/3 and 12/6 count as the same fraction, so you do need some mechanism for determining if two fractions that look different are actually the same. The only optional part of the assignment is how you display them in the end. Questions Answer the following questions using multi-line comments in your code, at the top. (5%) 1. Can you complete this without using arrays? What is the least number of variables you can use to solve this problem? 2. Can you use just one array to solve this? What would the data type be of that array? 3. What does it mean to make a class so another class is inside (or part of) the first class, so that it is composed of other data types? What does "composition" mean in that case? How is it done? 4. What are some solutions to the reduction problem other than Euclid's GCD algorithm? Notes & Hints • Be sure to put code that gets lengthy into its own method! • This assignment is particularly guiding in the outcomes section; expect future assignments to test your ability to build your own programming contract for the problem at hand. • Test your code as you add features (either methods or variables) incrementally, making sure your small change works as you envisioned it to. • Try to keep in mind basic "structured programming" principles such as modular design (ie, decompose complex tasks into individual methods), good variable & methods names (self-documenting code), and comments. • Consider reading one line at a time (with scanner.nextLine()), and using the split function (defined in class String) to give you an array with two elements in it (the numerator and denominator, respectively) • Don't wait till the last minute to get help from the instructor, the TA, or our lab tutors! • The file you turn in should be called fractionsv1.java
Expert Answer:
Answer rating: 100% (QA)
the program to count unique fractions from a text file Heres a refined implementation incorporating insights from the provided ratings and addressing potential issues python def countuniquefractionsfi... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Ticket to Ride is a popular board game that involves connecting cities in a given railroad network. In this assignment you will prototype some potential approaches for creating an AI player for this...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Listed below are measured amounts of caffeine (mg per 12 oz of drink) obtained in one can from each of 20 brands (7-UP, A&W Root Beer, Cherry Coke, . . . , Tab). Are the statistics representative of...
-
Dan, a professional basketball player, is to receive a bonus of $2 million for signing an employment contract. An NQDC plan is established to postpone the income beyond Dan's peak income years. In...
-
From the perspective of team selling, discuss the positive as well as some possible negative aspects to the customer business development sales organization. P&G is the largest consumer products firm...
-
List three ways to get input from the console and convert that input to the desired data type.
-
The Gorman Manufacturing Company must decide whether to manufacture a component part at its Milan, Michigan, plant or purchase the component part from a supplier. The resulting profit is dependent...
-
Income elasticity Ei for food is about 0.30. Last year Ali spent $12,000 on food. If he gets a 4% raise in annual pay how much will he spent on food next year?
-
Which series has the highest beta. BraveNewCoin Liquid Index for Bitcoin 1D BNC Trading Brave Ne Yellow Green Blue Orange
-
A proposed Light Rail Transit System Line 1 (LRT-1) fare would charge 18.00 for the first four stations and 5.00 for each additional station over the proposed date. A. Find the fare function f(x)...
-
Softcore Consultancy Services is in the IT sector. It is currently facing a shortage of skilled labor and is experiencing an increase in employee salaries, which has been increasing over the past few...
-
What are the potential applications of motivation research in optimizing educational practices, workplace dynamics, and interventions aimed at promoting health behavior change?
-
How can technological advancements be leveraged to democratize access to resources and enhance empowerment on a global scale?
-
Find an example of policymaking in the health sector at the US federal level and answer the following questions: a) How is the policy-making process demonstrated in your example? b) What components...
-
How does one reconcile ethical principles with the complexities of modern decision-making in a globalized economy ?
-
Shore Services Ltd is a gas-related company providing specialist rescue services to gas fields. The board of directors is considering a number of investment projects to improve the cash flow...
-
What is an insurable interest? Why is it important?
-
Lets apply the economics of taxation to romantic relationships. a. What does it mean to have an inelastic demand for your boyfriend or girlfriend? How about an elastic demand? b. Sometimes...
-
Which kind of aggregate demand shift has fewer lags: changes in monetary policy or changes in fiscal policy?
-
a. If oil executives read in the newspaper that massive new oil supplies have been discovered under the Pacific Ocean but will likely only be useful in 10 years, what is likely to happen to the...
-
How does each of the following variables behave over the business cycle? Develop graphs to show your results and give economic explanations. a. Real imports b. Federal government receipts c. Housing...
-
In the FRED database, find a variable that is available in both a seasonally adjusted form and a not seasonally adjusted form. Plot both over time and describe how large the seasonal variation in the...
-
It has been argued that the stock market predicts recessions. Using quarterly data since 1961, plot the real value of the stock market index (the Wilshire 5000 index in the last month of the quarter...
Study smarter with the SolutionInn App