The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 3 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I need help with these Questions. step by step instruction would be great.
Assignment 4(Total points 100)
Â
Problem 1
Write a method frequentFlier that accepts a Scanner for an input file of ticket type / mileage pairs and reports how many frequent-flier miles the person earned.
For example, given the input below, your method should return 15600 (2*5000 + 1500 + 100 + 2*2000).
firstclass 5000 coach  1500 coach
100 firstclass 2000Â discount 300
Â
Â
Problem 2
Write a method printDuplicates that accepts a Scanner for an input file. Examine each line for consecutive occurrences of the same token on the same line and print each duplicated token along how many times it appears consecutively. For example the file:
Â
hello how how are you you you you
I I I am Jack's Jack's smirking smirking smirking smirking smirking revenge
one fish two fish red fish blue fish
  bow wow wow yippee yippee  yo yippee  yippee yay yay yay
leads to the following console output:
how*2 you*4
I*3 Jack's*2 smirking*5
Â
wow*2 yippee*2 yippee*2 yay*3
Â
Problem 3
Write a method named coinFlip that accepts a Scanner for an input file of coin flips that are heads (H) or tails (T). Consider each line to be a separate set of coin flips and output the number and percentage of heads in that line. If it is more than 50%, print "You win!". Consider the following file:
Â
H T H H T
T t   t T h H
     h
For the input above, your method should produce the following output:
3 heads (60.0%)
You win!
Â
2 heads (33.3%)
Â
1 heads (100.0%)
You win!
Â
Problem 4
Write a method named flipLines that accepts a Scanner for an input file and writes to the console the same file's contents with each pair of lines reversed in order. For example, if the file contains:
Â
Twas brillig and the slithy toves
did gyre and gimble in the wabe.
All mimsey were the borogroves,
and the mome raths outgrabe.
Â
The End
your method should produce the following output:
did gyre and gimble in the wabe.
Twas brillig and the slithy toves
and the mome raths outgrabe.
All mimsey were the borogroves,
The End
Â
Problem 5
Â
Write a static method called runningSum that accepts as a parameter a Scanner holding a sequence of real numbers and that outputs the running sum of the numbers followed by the maximum running sum. For example if the Scanner contains the following data:
3.25 4.5 -8.25 7.25 3.5 4.25 -6.5 5.25
Your method should produce the following output:
running sum = 3.25 7.75 -0.5 6.75 10.25 14.5 8.0 13.25
max sum = 14.5
Â
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly