This assignment covers methods and classes, which are discussed in lectures. This homework also assumes understanding...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
This assignment covers methods and classes, which are discussed in lectures. This homework also assumes understanding of the concepts that are covered from the beginning of the course. The one programming exercise is worth 70 points. If you need help, ask the TAs, ask Tatiana, email the teaching assistants or Tatiana, come to office hours, etc. The rubric for this assignment is available canvas. What to hand in: For the programming task, upload two .java files to your Canvas account. The rubric has been posted to the course website. Programming Question - StockMarket and Trader.java - 100 points This programming section of this assignment requires you to submit TWO .java files. Please read all of the instructions, before you begin writing your code. Details were also provided during lecture. For this programming question, you'll be given a skeleton of a program, StockMarket.java, that contains pseudocode ONLY. The java file is well documented. Follow the instructions in the java file (from top to bottom), to write the code needed to finish this programming task. You'll also need to write a second file, called Trader.java. It is a class representing a person at a StockMarket, a trader. The Trader.java class has 4 fields, 6 methods (two of which take an argument, and four of which do not), and a non-default constructor, that takes a single argument. The setup is the following: The StockMarket.java program instantiates four objects of the class Trader, and for each of them declares a reference variable. The Trader class has fields for a person's name, his/her stocks gain percentage percentage (stockChangePercentage) (how "lucky" the Trader is, ranging from 0 (always loses) to 1 (always makes money)). In the StockMarket.java program, a while loop, with true as the condition, repeatedly prints out each Trader's name, how much money he/she has spent, how much money he/she currently has, and the Trader's net gain (or loss). At each iteration of the while loop, the program asks, "How much money should each Trader spend? Enter 0 to quit." If the user enters, via keyboard, 0, then a break statement is invoked, and the while loop (and hence program) terminates. If a non-zero value is entered, then the keepTrading method for each of the four Trader objects is invoked, which either increments or decrements each trader's money made, based on whether a randomly generated decimal number is more or less than a trader's stock change percentage. See the skeleton of StockMarket.java, which contains pseudocode of the entire program. The Trader.java class has four fields: traderName, stockChange Percentage, dollarsSpent, and dollarsMade. The class has a method, SetStockChange Percentage, that takes as input the single argument percentage of type double. The class has a second method, keepTrading, that takes as input the single argument dollars, of type double. The method CS110 Tatiana Harrison, CWU, HW5: Methods and Classes Page 1 of 4 Page 1 > of 4 ZOOM + keepTrading: generates a random number checks if that number is more or less than the Trader's stockChange Percentage; depending on the outcome, the method prints out to the console "made" or "lost". If a Trader makes money a round, the Trader's dollarsMade is incremented by 2 times the Trader's dollars. If a trader losses, they loose 3 times the amount od dollars being traded. Five additional methods, getTraderName, getDollarSpent, getStockChange Percentage, getDollarsMade, and getNetProfits, take no input parameters, and return a String, double, double, double, and double, respectively. The Trader class non-default constructor takes a single argument, name, of type String. See the skeleton of Trader.java, which explains each field, and the methods, in general. The UML diagram for the Trader class is shown below: traderName: String stock-ChangePercentage: double dollarsSpent : double - dollarsMade: double + getStockChangePercentage(): double + setStockChangePercentage(stockChangePercentage: double): void + keep Trading (dollarsBet : double): void + getTraderName(): String + getDollarsSpent(): double + getDollarsMade(): double + getNetProfit(): double + Trader(name: String): Trader A sample invocation of the program is shown in Figure 1, in which there are three rounds of playing the stock market. In the first round, $300 is bet by each player. In the second and third rounds, $160 and $1000 is bet by each player. Each player has a different chance of making money, and by the end of the three rounds of trading, two of the Traders have a negative net gain, and the player Happy, has a net of $800. Use Traders names and percentages used in this sample! List inputs that break code at the top of your Stock Market file. Here are the Traders, and their stock change percentages: Lucky's stock change percentage: 0.61 Grumpy's stock change percentage: 0.19 Happy's stock change percentage: 0.81 Sleepy's stock change percentage: 0.42 Trader Lucky; spent: $0.0; current $1000.0; net $1000.0 Trader Grumpy; spent: $0.0; current $1000.0; net $1000.0 Trader Happy; spent: $0.0; current $1000.0; net $1000.0 CS110 Tatiana Harrison, CWU, HW 5: Methods and Classes Page 2 of 4 Page 2 > of 4 ZOOM + Trader Sleepy; spent: $0.0; current $1000.0; net $1000.0 How much money should each Trader bet? Enter 0 to quit 300 Lucky lost money Grumpy lost money Happy made money Sleepy made money Trader Lucky; spent $300.0; current $100.0; net $-200.0 Trader Grumpy; spent $300.0; current $100.0; net $-200.0 Trader Happy; spent $300.0; current $1600; net $1300.0 Trader Sleepy; spent $300.0; current $1600.0; net $1300.0 How much money should each Trader bet? Enter 0 to quit 160 Lucky lost money Grumpy lost money money Happy lost money Sleepy made money Trader Lucky; spent $460.0; current $-1280.0; net $-1740.0 L Trader Grumpy; spent $460.0; current $-1280.0; net $-1740.0 Trader Happy; spent $460.0; current $220.0; net $-240.0 Trader Sleepy; spent $460.0; current $2520.0; net $2060.0 How much money should each Trader bet? Enter 0 to quit 120 Lucky lost money Grumpy lost money Happy made money Sleepy made money Trader Lucky; spent $580.0; current $-3020.0; net $-3600.0 Trader Grumpy; spent $580.0; current $-3020.0; net $-3600.0 Trader Happy; spent $580.0; current $1380.0; net $800.0 Trader Sleepy; spent $580.0; current $3680.0; net $3100.0 How much money should each Trader bet? Enter 0 to quit 0 Figure 1: sample output of the program StockMarket.java RUBRIC DO NOT ZIP FILES REMOVE MY COMMENTS, COME UP WITH YOUR OWN Item Stock Market.java program Main method completed Program compiles 4 Trader objects While loop is correct Inputs that break code Proper names, comments, code formatting, etc. Trader.java class Class has 4 fields Class has 6 methods Class has correct constructor Program compiles Inputs that break code CS110 Tatiana Harrison, CWU, HW 5: Methods and Classes Points Available 20 10 5 5 5 5 10 10 10 10 5 Page 3 of 4 Page 3 > of 4 ZOOM + This assignment covers methods and classes, which are discussed in lectures. This homework also assumes understanding of the concepts that are covered from the beginning of the course. The one programming exercise is worth 70 points. If you need help, ask the TAs, ask Tatiana, email the teaching assistants or Tatiana, come to office hours, etc. The rubric for this assignment is available canvas. What to hand in: For the programming task, upload two .java files to your Canvas account. The rubric has been posted to the course website. Programming Question - StockMarket and Trader.java - 100 points This programming section of this assignment requires you to submit TWO .java files. Please read all of the instructions, before you begin writing your code. Details were also provided during lecture. For this programming question, you'll be given a skeleton of a program, StockMarket.java, that contains pseudocode ONLY. The java file is well documented. Follow the instructions in the java file (from top to bottom), to write the code needed to finish this programming task. You'll also need to write a second file, called Trader.java. It is a class representing a person at a StockMarket, a trader. The Trader.java class has 4 fields, 6 methods (two of which take an argument, and four of which do not), and a non-default constructor, that takes a single argument. The setup is the following: The StockMarket.java program instantiates four objects of the class Trader, and for each of them declares a reference variable. The Trader class has fields for a person's name, his/her stocks gain percentage percentage (stockChangePercentage) (how "lucky" the Trader is, ranging from 0 (always loses) to 1 (always makes money)). In the StockMarket.java program, a while loop, with true as the condition, repeatedly prints out each Trader's name, how much money he/she has spent, how much money he/she currently has, and the Trader's net gain (or loss). At each iteration of the while loop, the program asks, "How much money should each Trader spend? Enter 0 to quit." If the user enters, via keyboard, 0, then a break statement is invoked, and the while loop (and hence program) terminates. If a non-zero value is entered, then the keepTrading method for each of the four Trader objects is invoked, which either increments or decrements each trader's money made, based on whether a randomly generated decimal number is more or less than a trader's stock change percentage. See the skeleton of StockMarket.java, which contains pseudocode of the entire program. The Trader.java class has four fields: traderName, stockChange Percentage, dollarsSpent, and dollarsMade. The class has a method, SetStockChange Percentage, that takes as input the single argument percentage of type double. The class has a second method, keepTrading, that takes as input the single argument dollars, of type double. The method CS110 Tatiana Harrison, CWU, HW5: Methods and Classes Page 1 of 4 Page 1 > of 4 ZOOM + keepTrading: generates a random number checks if that number is more or less than the Trader's stockChange Percentage; depending on the outcome, the method prints out to the console "made" or "lost". If a Trader makes money a round, the Trader's dollarsMade is incremented by 2 times the Trader's dollars. If a trader losses, they loose 3 times the amount od dollars being traded. Five additional methods, getTraderName, getDollarSpent, getStockChange Percentage, getDollarsMade, and getNetProfits, take no input parameters, and return a String, double, double, double, and double, respectively. The Trader class non-default constructor takes a single argument, name, of type String. See the skeleton of Trader.java, which explains each field, and the methods, in general. The UML diagram for the Trader class is shown below: traderName: String stock-ChangePercentage: double dollarsSpent : double - dollarsMade: double + getStockChangePercentage(): double + setStockChangePercentage(stockChangePercentage: double): void + keep Trading (dollarsBet : double): void + getTraderName(): String + getDollarsSpent(): double + getDollarsMade(): double + getNetProfit(): double + Trader(name: String): Trader A sample invocation of the program is shown in Figure 1, in which there are three rounds of playing the stock market. In the first round, $300 is bet by each player. In the second and third rounds, $160 and $1000 is bet by each player. Each player has a different chance of making money, and by the end of the three rounds of trading, two of the Traders have a negative net gain, and the player Happy, has a net of $800. Use Traders names and percentages used in this sample! List inputs that break code at the top of your Stock Market file. Here are the Traders, and their stock change percentages: Lucky's stock change percentage: 0.61 Grumpy's stock change percentage: 0.19 Happy's stock change percentage: 0.81 Sleepy's stock change percentage: 0.42 Trader Lucky; spent: $0.0; current $1000.0; net $1000.0 Trader Grumpy; spent: $0.0; current $1000.0; net $1000.0 Trader Happy; spent: $0.0; current $1000.0; net $1000.0 CS110 Tatiana Harrison, CWU, HW 5: Methods and Classes Page 2 of 4 Page 2 > of 4 ZOOM + Trader Sleepy; spent: $0.0; current $1000.0; net $1000.0 How much money should each Trader bet? Enter 0 to quit 300 Lucky lost money Grumpy lost money Happy made money Sleepy made money Trader Lucky; spent $300.0; current $100.0; net $-200.0 Trader Grumpy; spent $300.0; current $100.0; net $-200.0 Trader Happy; spent $300.0; current $1600; net $1300.0 Trader Sleepy; spent $300.0; current $1600.0; net $1300.0 How much money should each Trader bet? Enter 0 to quit 160 Lucky lost money Grumpy lost money money Happy lost money Sleepy made money Trader Lucky; spent $460.0; current $-1280.0; net $-1740.0 L Trader Grumpy; spent $460.0; current $-1280.0; net $-1740.0 Trader Happy; spent $460.0; current $220.0; net $-240.0 Trader Sleepy; spent $460.0; current $2520.0; net $2060.0 How much money should each Trader bet? Enter 0 to quit 120 Lucky lost money Grumpy lost money Happy made money Sleepy made money Trader Lucky; spent $580.0; current $-3020.0; net $-3600.0 Trader Grumpy; spent $580.0; current $-3020.0; net $-3600.0 Trader Happy; spent $580.0; current $1380.0; net $800.0 Trader Sleepy; spent $580.0; current $3680.0; net $3100.0 How much money should each Trader bet? Enter 0 to quit 0 Figure 1: sample output of the program StockMarket.java RUBRIC DO NOT ZIP FILES REMOVE MY COMMENTS, COME UP WITH YOUR OWN Item Stock Market.java program Main method completed Program compiles 4 Trader objects While loop is correct Inputs that break code Proper names, comments, code formatting, etc. Trader.java class Class has 4 fields Class has 6 methods Class has correct constructor Program compiles Inputs that break code CS110 Tatiana Harrison, CWU, HW 5: Methods and Classes Points Available 20 10 5 5 5 5 10 10 10 10 5 Page 3 of 4 Page 3 > of 4 ZOOM +
Expert Answer:
Answer rating: 100% (QA)
import javautil import javalang import javaio this class has to be inside Traderjava file Since here we cannot upload java file so i am upload single ... View the full answer
Related Book For
Fundamental Accounting Principles
ISBN: 978-0078110870
20th Edition
Authors: John J. Wild, Ken W. Shaw, Barbara Chiappetta
Posted Date:
Students also viewed these programming questions
-
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...
-
The statement of financial position of Kingbird Limited follows for the current year, 2020: KINGBIRD LIMITED Statement of Financial Position December 31, 2020 Current assets $135,660 Current...
-
The ruler of country Z has a terrible record of human rights violations. He has ordered the slaughter of civilians and has threatened to invade neighboring states. He has been working with known arms...
-
Dr. Cahill has been buying rugs for a home she bought last year. Today she received an email generated by CRM software that nudged her to buy yet another, in a style that happens to be consistent...
-
An electron and a proton are moving in circular orbits in the earth's magnetic field, high above the earth's atmosphere. The two particles move at the same speed. Which particle takes more time to...
-
Twelve years ago, Adams, Boyd, and Chambers formed a partnership manufacturing small circuit boards. Unfortunately, foreign competition, a softening economy, and management errors have led the...
-
Consider the following Java code: int lowerLimit; try { System.out.println("Entering the try block."); if (lowerLimit < 100) throw new Exception ("Lower limit violation.");...
-
Sigi is on a remote team. Today, he's working on a project that requires time flexibility with responses and feedback from his team members, who are all in different locations. Software with a chat...
-
A regular hexagon whose center is at the origin has one vertex on the positive y-axis at a distance of 3.5 feet from the center. Find the polar coordinates of the vertices and find the distance...
-
A shoe store is having a sale where each pair of shoes is sold for the same price and each pair of sandals is sold for the same price. Gloria purchased 4 pairs of shoes and 3 pairs of sandals for...
-
Pedro is doing laps around a track. Pedro can run 2 miles per hour faster than he can walk around the track. If Pedro walks around the track in 20 minutes and runs around the track in 15 minutes, at...
-
The following are the assets and liabilities of John Dunn Realty Company, as of August 31, 2021. Also included are revenue, expense, and selected stockholders' equity figures for the year ended on...
-
A farmer plans to plant 270 acres of his farm with wheat and soybeans. For every 2 acres of land planted with soybeans, the farmer wants to plant 7 acres of land with wheat. The farmer uses the...
-
n-1 O a. (n? 1) O b. 5 (n + 1) O c. n(n+1) 2 O d. n(n + 1)(2n + 1) O e. 00 O f. n3 O g. (n + 2) (n2 1) O h. n(n 1)(2n 1) O i. "(n+1)(2n+1) 6
-
A stock has had returns of 8 percent, 26 percent, 14 percent, 17 percent, 31 percent, and 1 percent over the last six years. What are the arithmetic and geometric average returns for the stock?
-
If a company recorded accrued salaries expense of $500 at the end of its fiscal year, what reversing entry could be made? When would it be made?
-
In January 2011, InTech Co. pays $1,350,000 for a tract of land with two buildings. It plans to demolish Building A and build a new shop in its place. Building B will be a company office; it is...
-
Refer to information in Exercise 19-7. Prepare the journal entry to allocate (close) over-applied or under-applied overhead to Cost of GoodsSold. April 30 May 31 Inventories Raw materials ...._ ....
-
In the wake of the financial crisis of 20072009, would you expect the banklending channel to have become more or less important in the United States? Explain your answer.
-
How might the concept of GDP at Risk help central banks pursue a financial stability objective?
-
Recent financial regulatory reforms have eased capital requirements for banks. Under what circumstances might lowering capital requirements affect economic growth?
Study smarter with the SolutionInn App