in Java and make sure the extra credit is in the program aswell

Code-
import java.util.*;
class Animal{
int age,amount;
String name,food;
//toString method to convert
public String toString(){
return "Name : "+name+" Age : "+age+" Amount : "+amount+" Food :
"+food;
}
//NO ARGUEMENT CONSTRUCTOR
Animal(){
name = "unknown";
age = 0;
amount = 0;
food = "none";
}
}
public class Main
{
public static void main(String[] args) {
//ANIMAL NAME
String[] names =
{"Rhino","Deer","Snake","Elephant","Cat"};
//ANIMAL FOOD
String[] foods = {"Grass","Oats","Fish","Meat"};
Random r = new Random();
//15 ANIMAL Object
Animal obj[] = new Animal[15];
int i;
//INITALZIE OBJECT TO NULL
for(i = 0 ; i<15;i++){
obj[i] = new Animal();
}
//generate random value for animal object
for( i = 0 ;i<15;i++){
obj[i].name = names[r.nextInt(5)];
obj[i].age = r.nextInt(13)+2;
obj[i].amount = r.nextInt(45)+5;
obj[i].food = foods[r.nextInt(3)];
}
//sort the animal object according to age
int n = obj.length;
for (i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (obj[j].age > obj[j+1].age)
{
// swap temp and arr[i]
Animal temp = obj[j];
obj[j] = obj[j+1];
obj[j+1] = temp;
}
//calculate the cost of each animal
int rhinoAmount=0,
deerAmount=0,snakeAmount=0,elephanAmount=0,catAmount=0;
for( i = 0 ;i<15;i++){
if(obj[i].name=="Rhino")
rhinoAmount+=obj[i].amount*foodType(obj[i]);
if(obj[i].name=="Deer")
deerAmount+=obj[i].amount*foodType(obj[i]);
if(obj[i].name=="Snake")
snakeAmount+=obj[i].amount*foodType(obj[i]);
if(obj[i].name=="Elephant")
elephanAmount+=obj[i].amount*foodType(obj[i]);
if(obj[i].name=="Cat")
catAmount+=obj[i].amount*foodType(obj[i]);
}
//print the animal object in sort according to age
for(i =0;i<15;i++){
System.out.println(obj[i].toString());
}
System.out.println("The total cost to feed Rhino per day is
$"+rhinoAmount);
System.out.println("The total cost to feed Deer per day is
$"+deerAmount);
System.out.println("The total cost to feed Snake per day is
$"+snakeAmount);
System.out.println("The total cost to feed Elephant per day is
$"+elephanAmount);
System.out.println("The total cost to feed Cat per day is
$"+catAmount);
}
static int foodType(Animal a){
if(a.food=="Grass")
return 1;
if(a.food=="Oats")
return 2;
if(a.food=="Fish")
return 5;
if(a.food=="Meat")
return 8;
else
return 0;
}
}
Screenshots -

Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able to store information regarding the name, age, gpa, and phone number of a Student object. Please write all the setter and getter methods. Finally, write a Demo class to demonstrate the use of the class by creating two different objects. 2.Use the same Student class from the previous problem. This time,you will write a different Demo class, in which you will create three Student...
JavaScript - Sorting Assignment (arrays, classes, functions and
higher order functions)
Note: Please make sure to use the
ES6 keyword style =>
instead of the older function. For variables please use keyword
let, not var, class and within
the constructor, not function.
Instructions:
- Create a new JavaScript file and name
it “Objects.js”
- Create a class and make sure to use “names” as the
identifier.
- Create a constructor with the following
elements:
first ( value passed will be...
In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...
C# - Inheritance exercise
I could not firgure out why my code was not working. I was
hoping someone could do it so i can see where i went wrong.
STEP 1: Start a new C# Console Application project and rename its main class Program to ZooPark. Along with the ZooPark class, you need to create an Animal class. The ZooPark class is where you will create the animal objects and print out the details to the console. Add the...
Chapter 5 Assignment Read directions: In JAVA design and implement a class called Dog that contains instance data that represents the dog's name and dog's age. Define the Dog constructor to accept and initialize instance data. Include getter and setter methods for the name and age. Include a method to compute and return the age of the dog in "person years" (seven times age of dog. Include a toString method that returns a one-time description of the dog (example below)....
Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store { public final double SALES_TAX_RATE = 0.06; private String name; /** * Constructor to create a new store * @param newName */ public Store(String newName) { name = newName; } ...
Java Programming The following is about creating a class Fish and testing it. In every part, correct any syntax errors indicated by NetBeans until no such error messages. (i) Create a class Fish with the attributes name and price. The attributes are used to store the name and the price of the fish respectively. Choose suitable types for them. You can copy the class Counter on p.17 of the unit and modify the content. Copy the content of the file...
The goal of this homework is to write a small database system for an Animal Shelter. This is a no-kill shelter like the one just west of the Addition Airport. You will accept animal “donations” to the shelter, but mostly only dogs and cats. (But yes, there may be the occasional hamster or other nondog, non-cat animal donation.) At present, all we need to do is write the skeleton of a database that will track all the animals in the...
Write a program in a class SandwichCounter that computes the cost of sandwiches sold at a food stand. Three kinds of sandwiches —cheese steak, chicken, and salad— are cost, respectively, $8.5, $7.5, and $7.0 per sandwich. Create an array of strings that holds the names of these sandwiches. Create another array that holds the cost of each corresponding sandwich. Your program should read the name of a sandwich and the quantity desired by a customer. Locate the sandwich in the...
( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...