Set up your directory:
$ mkdir -p ~/cs180/lab14 $ cd ~/cs180/lab14 $ drjava &
3 4 +
rather than 3 + 4
. If there are multiple operations, the operator is given immediately after its second operand; so the expression written 3 − 4 + 5
in conventional notation would be written 3 4 − 5 +
in RPN: 4 is first subtracted from 3, then 5 added to it.3 − 4 × 5
can also be written 3 − (4 × 5)
, that means something quite different from (3 − 4) × 5
. In postfix, the former could be written 3 4 5 × −
, which unambiguously means 3 (4 5 ×) −
which reduces to 3 20 −
; the latter could be written 3 4 − 5 ×
(or 5 3 4 − ×
, if keeping similar formatting), which unambiguously means(3 4 −) 5 ×
.÷ 6 3
in Polish notation and 6 3 ÷
in reverse Polish both evaluate to 2, whereas 3 6 ÷
; in reverse Polish notation would evaluate to ½).The infix expression
5 + ((1 + 2) × 4) − 3
can be written down like this in RPN:
5 1 2 + 4 × + 3 −
Input | Operation | Stack | Comment |
---|---|---|---|
5 | Push value | 5 | – |
1 | Push value | 1,5 | – |
2 | Push value | 2,1,5 | – |
+ | Add | 3,5 | Pop two values (1, 2) and push result (3) |
4 | Push value | 4,3,5 | – |
x | Multiply | 12,5 | Pop two values (3, 4) and push result (12) |
+ | Add | 17 | Pop two values (5, 12) and push result (17) |
3 | Push value | 3,17 | – |
– | Subtract | 14 | Pop two values (17, 3) and push result (14) |
Result | 14 | – |
Evaluator
with a static
class method evaluate
that takes a String
argument comprising an RPN expression and returns the int
result.String
argument to calls to evaluate
to check the results.HashMap
) is a data structure used to implement an associative structure that maps keys to values.HashMap
: http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.htmlimport java.util.HashMap; import java.util.Map;
HashMap
used to track integer counts is:get()
null
, it simply means that the word doesn’t exist in the map.put()
:
map.put(word, count);
put
are the word (String
) and count (int
) which is the total number of times the number is seen. To fetch the count of a given word, use the get()
function.You work for an esteemed sports news website. The big story is that the NBA is having a special all star league, in which teams are assigned randomly before each game. The winner(s) of the competition are the players who are in the most winning teams. Your team has developed a way to organize a file so that your reports come in faster than any other website.
Input file
The file is formatted as follows in which each line represents one game: The first token is an integer that can be either 1
or 0
. It is 1
if the first team won and it is 0
if the second team won.
This token is followed by exactly five tokens representing the player names of the first team (separated by spaces). After that, the token vs
token follows and finally five tokens for the player names of the second team.
For example, this line means the second team with players Prelich Murphy Wilkes Gall Greenberg has won :
0 Chan Stine Neilson Curtis Kennedy vs Prelich Murphy Wilkes Gall Greenberg
Stats
with a static
class method wins
that reads lines of input from a BufferedReader and computes winner statistics for each of the players mentioned in the input, by constructing a HashMap
mapping the names of the players (String
) to the number of wins (Integer
) that player has accumulated, and returns the resulting HashMap
.static
class method winner
that iterates through a HashMap
, such as returned by wins
, returning the name of the player with the most wins (in the case of a tie, return any such player).You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more