The Pet class should also have the following methods:
2. Write a test class to test your Pet class. Make sure you have three different types of pets. (three Pet objects)
Method overriding to calculate simple interestCreate an abstract class Bank with method calculateSimpleInterest method which takes the amount of type double and time of type int (in years) as parameters and returns double type simple interest with interest at 6 PPA.
Create classes BankA, BankB and BankC which extends class Bank and override the method calculateSimpleInterest. Class BankA, BankB, and BankC calculate the interest at 10 PPA, 9 PPA, and 7 PPA respectively in an overridden method.
Input
1
45000
3
where,
Output
13500.00
where the output in 2 decimal numbers.
Create a Java ArrayList of String type “fromCity”, use “Add()” method to add three elements: “Los Angeles”, “San Francisco”, and “Portland”. Create another Java ArrayList of String type “toCity” with three elements: “Seattle”, “Denver”, and “Chicago”. Make two-dimensional array of int type named “distance” whose elements are from table. Be sure to make the elements using the index of [from][to].
4x4 Table:
fromCity \ toCity | 0 | 1 | 2 | 3
0 |1135 | 1016 | 2015
1 | 807 | 1250 | 2128
2 | 174 | 1240 | 2121
Ask user to enter name of city to “travel from”, use “indexof()” method to find the index of the given city in the “fromCity” ArrayList.
Ask user to enter the name of city to “travel to”, then use“indexOf()” method to find the index of the given city in the “toCity” ArrayList. Find “distance” array and display it.
Write a program that computes the area of a circular region (the shaded area in the diagram), given the radii of the inner and the outer circles, ri and ro, respectively.
Create a Java ArrayList of String type “fromCity”, use “Add()” method to add three elements: “Los Angeles”, “San Francisco”, and “Portland”. Create another Java ArrayList of String type “toCity” with three elements: “Seattle”, “Denver”, and “Chicago”. Make two-dimensional array of int type named “distance” whose elements are from table. Be sure to make the elements using the index of [from][to].
4x4 Table:
fromCity \ toCity | 0 | 1 | 2
0 | 1135 | 1016 | 2015
1 | 807 | 1250 | 2128
2 | 174 | 1240 | 2121
Ask user to enter the name of city to “travel from”, use “indexof()” method to find the index of the given city in the “fromCity” ArrayList.
Ask user to enter the name of city to “travel to”, then use“indexOf()” method to find the index of the given city in the “toCity” ArrayList. Find “distance” array and display it.
a. An algorithm is a procedure for solving a problem in terms of the actions to execute and the order in which these actions execute. Write an algorithm for the implementation of the sentinel control in Question A Sub Question.
B. For larger datasets, a linear search may be inadequate or perhaps inefficient. What other search method can be employed to return the maximum number from a set of elements in an array. Explain your answer. [5 marks]
I. Identify and correct the errors in each of the following sets of code: [6 marks] i.
while ( c <= 5 ) {
product *= c; ++c;
ii. if ( gender == 1 )
System.out.println( "Woman" );
else;
System.out.println( "Man" );
iii. What is wrong with the following while statement?
while ( z >= 0 )
sum += z;
D. Explain two (2) programming situations that will require the use of overloaded methods [5 marks]
Write a java program that reads three (3) int variables and performs the below operations:
i. Prints out their product
ii. Prints out the maximum of the numbers Do not use any inbuilt Java Methods to return the maximum. Extra marks will be awarded for clarity of code and comments. [8 marks]
B. Algorithms perform differently on different data sets and as such we may be interested in either their Best-case, Worst-case or Average-case scenarios. Explain why the Worst-case for an insertion sort is with reverse-sorted data. [6 marks]
C. Identify and correct the errors in each of the following sets of code: [6 marks]
i. while ( c <= 5 )
{
product *= c; ++c;
ii. if ( gender == 1 )
System.out.println( "Woman" );
else;
System.out.println( "Man" );
iii. What is wrong with the following while statement?
while ( z >= 0 )
sum += z;
D. Explain two (2) programming situations that will require the use of overloaded methods [5 marks]
A).Consider a problem to find the student who had the highest GPA for the 2020/2021 academic year.
i. Explain your choice of either a search or a sorting algorithm to solve this problem. [7.5 marks]
ii. Write the algorithm for your implementation. [7.5 marks]
B). Consider the analogy of a pile of books on a table. Using a diagram, explain the basic operations involved in adding a book to the pile and removing a book from the pile. [5 marks]
C). Use the code below to answer the questions that follow: [5 marks]
public class CS204 { public static int linearSearch(int[] data, int target) {
for (int i = 0; i < data; i++) {
if (target == data[i]){
return i;
}
}
return -1;
}
public void main(String[] args) {
int[] data = {3, 14, 7, 22, 45, 12, 19, 42, 6}; System.out.println("Search for 7: " + linearSearch(7));
}
}
i). Why is method linearSearch declared static? Identify and resolve the errors in the code.
ii) identify nd resolve the errors in the code.