Question: Write a program in Java, ( 1 ) fibonacci - Takes as argument a single non - zero, positive integer and prints the fibonacci series

Write a program in Java,
(1) "fibonacci" - Takes as argument a single non-zero, positive integer and prints the fibonacci series up to the highest fibonacci number that is smaller or equal to the input
argument. The output should be in ascending order with a single space character separating each integer.
Eg: If "15" is the input argument, the output would be "011235813"."15" is not a fibonacci number so we print up to the highest fibonacci number that is less than or equal
to "15"; in this case that is "13".
Eg: If "21" is the input argument, the output would be "01123581321"."21" is a fibonacci number, so we print all the fibonacci numbers up to and including "21".
Eg: If "1" is the input argument, the output would be "011".
If the input argument is anything other than a positive, non-zero integer, you must print the string "error".
Eg: If "-6" is the input argument, output must be "error".
Eg: If "helloworld" is the input argument, output must be "error"
Eg: If "0" is the input argument, the output must be "error".
(2) "overlap" - Takes as argument a list of ranges and determines whether any two ranges overlap. If there is any overlap, it prints "true", otherwise it prints "false".
A range is given in the form "a,b", where a and b are both integers and where a <= b. Note that a and b can be negative, zero or positive. A list of ranges is a sequence of
ranges separated by a single space character (""): "a,b x,y j,k". Two ranges overlap if they partially, or fully cover the same set of integers. For example: "3,6" and "5,9"
overlap because they both include 5 and 6. Similarly, "8,176" and "6,11" also overlap because they both include 8,9,10 and 11. On the other hand, "17,17" and "-5,4" do not
overlap because they do not share any integers.
If you encounter a malformed range, you must print "error". A malformed range, "a,b", is one where either a or b are not integers or where a > b.
For example, the following ranges are all malformed "17,4","-1,-5", "five,9","1,$*$", "hello,world".
The "overlap" function is guaranteed to be given a list of at least two intervals, therefore you need not worry about an empty list or a single
range as arguments.
Eg: Given "17,2001,217,178,9" as input, the function would print "true" because "17,200" and "17,17" overlap.
Eg: Given "8,994,71,3" as input, the function would print "false" because no ranges overlap.
Eg: Given "4,8 dd,5" as input, the function would print "error" because "dd,5" is a malformed range.
(3) "stats" - Takes no arguments and prints the number of calls to "fibonacci" and "overlap" (in that order) as two integers, on a single line, separated by a single space
character ("").
Eg: If "fibonacci" is called three times, and "overlap" is called twice, the output should be "32"
The input to your program will be given on stdin and will consist of one function call per line. Each line starts with a string ("fibonacci",
"overlap" or "stats"), indicating which function is being called. Following the function name, there will be a single space character (""),
after which the input to the function (if any) is presented. If "stats" is called, it will always be the last function call.
-----------------------
Sample input:
fibonacci 21
overlap 8,994,71,3
fibonacci 0
fibonacci 15
overlap 1,310,17-10,02,4
stats
Sample output:
01123581321
false
error
011235813
true
32
-----------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!