Question
Could anyone help me with ArrayReverser, LeapYear , ExceptionZero . so that I could understand it better thanks advance. Reverser.java public class Reverser extends Presenter{
Could anyone help me with ArrayReverser, LeapYear , ExceptionZero . so that I could understand it better thanks advance.
Reverser.java
public class Reverser extends Presenter{ // method to reverse an array and displaying it public static int[] reverse(int a[]) { int[] b = new int[n]; int j = n; for (int i = 0;...) { // complete for loop definition // do some coding } return b; } // info has to return a content for an array {1, 2, 3{ like // <1, 2, 3> public static void main(String[] args) { int [] arr = {10, 20, 30, 40, 50}; Rerverser r = new Reverser(arr); r.reverse(); } }
LeapYear.java
import java.util.Scanner;
// Leap year occurs in a year which is an integer multiple of 4 (except for years evenly divisible by 100, // which are not leap years unless evenly divisible by 400)
// The following code is not working for all leap years. Modify LeapChecker() to fix it.
public class LeapYear { public static String LeapChecker(int year) { boolean isLeap = false; if(year % 4 == 0) { if(year % 100 == 0) { // some coding is required isLeap = false; } else isLeap = true; } else { isLeap = false; } if(isLeap == true) return(year + " is a Leap Year."); else return(year + " is not a Leap Year."); } public static void main(String[] args) { int year; Scanner scan = new Scanner(System.in); System.out.println("Enter any Year:"); year = scan.nextInt(); scan.close(); System.out.println(LeapChecker(year)); } }
ExceptionZero.java
class ExceptionZero { public static String divideMethod(int a, int b) { // Modify this method to catch appropriate exception and return exception e.toString()
int result = a/b; // don't modify the return statement return String.valueOf(result); } public static void main(String[] args) { System.out.println(divideMethod(20, 0)); } }
...................................
Presenter.java
public abstract class Presenter {
public abstract String info();
}
SReverser.java
import java.util.Arrays;
// reverse only the part of the array indicated by index (from, to)
// example
// {1, 2, 3}
// reverse(2,3) would give
// {1, 3, 2}
// throw an excpetion, if bound are negative, or if to > from
public class SReverser extends Reverser{
public SReverser(int[] a) throws EmptyArrayException {
// need some code
}
public int[] reverse(int from, int upTo) throws InvalidBoundsException{
// need some code
}
}
EmptyArrayException.java
public class EmptyArrayException extends Exception {
private static final long serialVersionUID = 42L;
public class EmptyArrayException extends Exception {
public EmptyArrayException() {
System.out.println("Array reference is null");
}
}
InvalidBoundsException.java
public class InvalidBoundsException extends Exception {
private static final long serialVersionUID = 43L;
public InvalidBoundsException() {
System.out.println("Invalid Bounds exception");
}
}
Step by Step Solution
3.47 Rating (147 Votes )
There are 3 Steps involved in it
Step: 1
Lets go through each of the provided classes and methods to understand them better Reverserjava This ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started