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 method called

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 "PrintInfo" 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 PrintInfo() 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_array1 = getLastNumber(array_one); int[] array_two = {6, 3, 11, 46, 78}; int[] array_three = {2, 9, 1, 7, 97}; } }

a. 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_lastIndex(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

Step: 3

blur-text-image

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

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

Evaluate Keller-Globes approach to training.

Answered: 1 week ago

Question

Different formulas for mathematical core areas.

Answered: 1 week ago