Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write in java 1. Implement the code for a class called Animal with the following: - Attributes: String Nutrition, String Shape, Boolean pet. - A

image text in transcribed

write in java 1. Implement the code for a class called "Animal" with the following: - Attributes: String Nutrition, String Shape, Boolean pet. - A method called "PrintInfo" that prints all the information of the Animal class. - Reuse class Animal to create class called "Horse" o Additional attributes: string colour, int age. o Override the method "Printlnfo" by printing all the information of horse instances. Write the code to show example of instances of Animal class: - Create an instance for a horse class by calling a constructer has ("Grass","Big",false,"Black",3) - Print the information of the class through Printlnfo() 2. Implement the code for: a. A static method called "getLastNumber" that takes an integer array and return the last the number. class Main \{ public static void main(String[] args) \{ int[] array_one ={12,4,5,2,5}; int last_array 1 = getLastNumber(array_one); int[] array_two ={6,3,11,46,78}; int[] array_three ={2,9,1,7,97};}} b. A static method called "getTotal_lastIndex" that takes 3 integer arrays and return the sum of the last the number of each array. getTotal_lastIndex should reuses getLastNumber. class Main \{ public static void main(String[] args) \{ int[] array_one ={12,4,5,2,5}; int[] array_two ={6,3,11,46,78}; int[] array_three ={2,9,1,7,97}; int myTotal = getTotal_lastlndex(array_one,array_two,array_three); }} 3. Run the following code in Java compiler: public class Main \{ public static void main(String[ ] args) \{ int[] myNumbers ={1,2,3}; System.out.println(myNumbers[10]); }} Then use try catch statement to solve the error caused by calling the array with index not found in the array

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions