Executable code
//Include the needed packages
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.SpringLayout;
//Class
public class XXXX_Program5
{
//Class
class Animals
{
//Declare needed
variables
private String
ownerName;
private int birthYear;
private double
billBalance;
private String species;
private String
speciesSpecialFeature;
//Parameter constructor
public Animals(String
ownerName,
int birthYear,
double billBalance,
String species,
String
speciesSpecialFeature)
{
//Initialize
super();
this.ownerName = ownerName;
this.birthYear = birthYear;
this.billBalance = billBalance;
this.species = species;
this.speciesSpecialFeature = speciesSpecialFeature;
}
//Getter method
public String
getOwnerName()
{
//Return
return
ownerName;
}
//Setter method
public void
setOwnerName(String ownerName)
{
//Set
this.ownerName = ownerName;
}
//Getter method
public int getYear()
{
//Return
return
birthYear;
}
//Setter method
public void setYear(int
birthYear)
{
//Set
this.birthYear = birthYear;
}
//Getter method
public double
getBillbalance()
{
//Return
return
billBalance;
}
//Setter method
public void
setBillbalance(double billBalance)
{
//Set
this.billBalance = billBalance;
}
//Getter method
public String
getSpecies()
{
//Return
return
species;
}
//Setter method
public void setSpecies(String
species)
{
//Set
this.species = species;
}
//Getter method
public String
getSpecialFeature()
{
//Return
return
speciesSpecialFeature;
}
//Setter method
public void
setSpecialFeature(String speciesSpecialFeature)
{
//Set
this.speciesSpecialFeature = speciesSpecialFeature;
}
//Method toString()
public String
toString()
{
//Declare
a variable
String
retStr = "";
//Update
retStr
retStr ="
Owner : "+this.getOwnerName()+
" Year :
"+this.getYear()+
"
BillBalance : "+this.getBillbalance()+
" Species
: "+this.getSpecies();
//Return
return
retStr;
}
}
//Derived class
class Mammals extends Animals
{
//Parameter constructor
public Mammals(String
ownerName,
int birthYear,
double billBalance,
String species,
String
speciesSpecialFeature)
{
//Initialize
super(ownerName, birthYear, billBalance, species,
speciesSpecialFeature);
}
//Method toString()
public String
toString()
{
//Declare
a variable
String
retStr = "";
//Update
retStr
retStr ="
Owner : "+this.getOwnerName()+
" Year :
"+this.getYear()+
"
BillBalance : "+this.getBillbalance()+
" Species
: "+this.getSpecies();
//Update
retStr
retStr =
retStr + " No. of Legs : "+this.getSpecialFeature();
//Return
return
retStr;
}
}
//Derived class
class NonMammals extends Animals
{
//Parameter constructor
public NonMammals(String
ownerName,
int birthYear,
double billBalance,
String species,
String
speciesSpecialFeature)
{
//Initialize
super(ownerName, birthYear, billBalance, species,
speciesSpecialFeature);
}
//Method toString()
public String
toString()
{
//Declare
a variable
String
retStr = "";
//Update
retStr
retStr ="
Owner : "+this.getOwnerName()+
" Year :
"+this.getYear()+
"
BillBalance : "+this.getBillbalance()+
" Species
: "+this.getSpecies();
//Update
retStr
retStr =
retStr +" Blood Type : "+this.getSpecialFeature();
//Return
return
retStr;
}
}
//Method readAnimalsfromFile()
public static Animals[]
readAnimalsfromFile()
{
//Array
Animals [] animalArr =
null;
//Create instance
XXXX_Program5 obj1 = new
XXXX_Program5();
//Create instance
BufferedReader br1 =
null;
//Create instance
FileReader fr1 = null;
//Declare variables
int lineCounter =0;
int numOfAnimals = 0;
//Try
try
{
//Input
file
fr1 = new
FileReader("program5.txt");
//Buffered
reader
br1 = new
BufferedReader(fr1);
//Declare
variables and initialize
String
ownerName= "";
int
birthYear = 0;
double
billBalance=0;
String
species = "";
String
speciesSpecialFeature="";
String
presentLine;
//Loop
while
((presentLine = br1.readLine()) != null)
{
//Condition check
if(lineCounter == 0)
{
//Update
numOfAnimals
=Integer.valueOf(presentLine);
//Update
animalArr = new
Animals[numOfAnimals];
}
//Otherwise
else
{
//Declare a variable
String[] inArr =
presentLine.split(" ");
//Loop
for(int
i1=0;i1<inArr.length;i1++)
{
//Condition check
if(0 ==
i1)
{
//Update
ownerName = inArr[i1];
}
//Condition check
else if(1
== i1)
{
//Update
birthYear = Integer.valueOf(inArr[i1]);
}
//Condition check
else if(2
== i1)
{
//Update
billBalance = Double.valueOf(inArr[i1]);
}
//Condition check
else if(3
== i1)
{
//Update
species = inArr[i1];
}
//Condition checkc
else if(4
== i1)
{
//Update
speciesSpecialFeature=inArr[i1];
}
}
//Create instance
Animals newAnimals
=null;
//Condition check
if("M".equalsIgnoreCase(species))
{
//Update
newAnimals
= obj1.new Mammals(ownerName, birthYear, billBalance, species,
speciesSpecialFeature);
}
//Condition check
else
if("N".equalsIgnoreCase(species))
{
//Update
newAnimals
= obj1.new Mammals(ownerName, birthYear, billBalance, species,
speciesSpecialFeature);
}
//Update
animalArr[lineCounter-1]
=newAnimals;
}
//Increment
lineCounter++;
}
}
//Catch block
catch (IOException e)
{
//Error
e.printStackTrace();
}
//Return
return animalArr;
}
//Method sortAnimalsArray()
public static Animals[] sortAnimalsArray(Animals
[] animalArr )
{
//Declare variables
int n =
animalArr.length;
double tmp = 0;
//Loop
for(int i1=0; i1 < n;
i1++)
{
//Loop
for(int
j1=1; j1 < (n-i1); j1++)
{
//Condition check
if(animalArr[j1-1].getBillbalance() >
animalArr[j1].getBillbalance())
{
//Swap
tmp =
animalArr[j1-1].getBillbalance();
animalArr[j1-1].setBillbalance(animalArr[j1].getBillbalance());
animalArr[j1].setBillbalance(tmp);
}
}
}
//Return
return animalArr;
}
//Method displayArray()
public static void displayArray(Animals []
animalArr)
{
//Loop
for(int i1=0; i1 <
animalArr.length; i1++)
{
//Display
System.out.print(animalArr[i1] + "\n");
}
}
//Driver
public static void main(String [] args)
{
//Function call to read file
input
Animals [] animalArr =
readAnimalsfromFile();
//Display
System.out.println("List of
Animals Before Sorting : ");
//Function call
displayArray(animalArr);
//Function call
animalArr =
sortAnimalsArray(animalArr );
//Display
System.out.println("List of
Animals After Sorting : ");
//Function call
displayArray(animalArr);
}
}
The purpose of this project is to give students more exposure to object oriented design and...
Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make Chicken and Cow as subclasses of Dairy. The Sheep and Dairy classes implement the Edible interface. howToEat) and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML...
(The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make implement the Edible interface. howToEat() and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML diagram for the classes and the interface 2. Use Arraylist class to create an...
Write in java language ================== Office Supplies Inc., an office supply store, services many customers. As customers’ orders for office supplies are shipped, information is entered into a file. Office Supplies bills their customers once each month. At the end of each month, the Chief Executive Officer requests a report of all customers sorted by their customer id (from lowest to highest). The report includes their bill balance and tax liability. Write a program to produce the outstanding balance report...
Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...
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...
This lab serves as an intro to Java Interfaces and an Object-Oriented design strategy towards implementing data structures. We will be using Entry.java objects which are key,value pairs, with key being an integer and value being a generic parameter. We will be sorting these Entries according to their key value. The file Entry.java is given to you and does not require any modification. As you should know by now, bucket sort works by placing items into buckets and each bucket...
Hi this program must be completed using a Eclipes Compiler for Java only . This is and intro to java class , so only intro methods should be used for this assignment. Please include a copy of the input data and a sample of the out put data . Thanks a bunch Homework-Topic 9-Donations Write a complete program to do the following: The main program calls a method to read in (Erom an input file) a set of people's three-digit...
JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...
Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one menu item called Search. Clicking on search should prompt the user using a JOptionPane input dialog to enter a car make. The GUI should then display only cars of that make. You will need to write a second menu...
Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program: Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...