Question: can you fix this code to use object oriented programing and incorporate error trapping for invalid inputs import java.io.*; import java.util.Scanner; public class main {

can you fix this code to use object oriented programing and incorporate error trapping for invalid inputs

import java.io.*; import java.util.Scanner;

public class main { public static int fib(int n) { if(n<=1){ throw new IllegalArgumentException("n must be >=0"); } else if (n<2) { return n; } else{ return fib(n-1)+fib(n-2); } } public static void main (String args[]) { int n,flag=1; while(flag==1){ System.out.println(" Enter the integer: "); //scanner Scanner s= new Scanner(System.in); n=s.nextInt(); //checking result 0-46 bounds if(n<0 && n>46) System.exit(0); System.out.println(fib(n)); System.out.println("Want more fibonacci calculation(1/0)"); flag=s.nextInt(); } } }

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 Databases Questions!