1) Given an array of int[ ]; write code that will sort the array of int using a bubble sort algorithm.

2) What is the output of the following code:

int prod=0;
for (int x=3; x<=5 x++) {
for (int y=3; y<=7; y++) {
prod = x * y;
if (prod % 3 == 0)
System.out.println(prod);
}
}

3) Write a method called examGrade that will grade a 20 question multiple choice exam consisting of A,B,C,D answers. The exam_answers is an array of char (char[ ]) passed into the method consisting of student answers. Compare the exam_answers with the answer_key in an array of (char[ ]) - answer key is predefined. Each question is worth 5 points for a total of 100 points: The method will grade each exam passed in as a parameter and return a grade for the exam based on the following:

A = any value between 90 and 100
B = any value between 80 and less than 90
C = any value between 70 and less than 80
F = less than 70

char examGrade (char[ ] exam_answers) {
// all char have ‘ ‘ (single quote)
char[ ] answer_key = {A,D,C,A,B,B,A,D,B,C,C,A,D,B,C,D,B,A,B,A};
}

EG:

Student 1 has exam_answers = {B,D,C,A,B,C,A,D,B,C,A,A,D,B,C,D,B,A,B,A};
17 correct; 3 incorrect; exam_score = 85; grade=B

Student 2 has exam_answers = {A,D,C,A,B,B,A,D,B,C,C,A,D,B,C,D,B,A,B,A};
20 correct; 0 incorrect; exam_score=100; grade=A

4) Given the following Object:

class Account {
private String name;
private double balance;

Account ( ) { }
Account (String nm) { }
Account (String nm, double bal) { }
public void setName(String nm) { // set name }
public String getName( ) { // returns name }
public double getBalance( ) { // returns balance }
public void setBalance (double bal ) { // set balance variable }
public double calcMonthlyInterest( ) { } // calculate the monthly interest amount
public double calcMonthlyInterest (double intRate) { }// calculate the monthly interest
// amt given a rate
}

a) Implement the following interface for Account Object. The getClientBalance() will return the balance of Account.

interface Balance {
public double getClientBalance(); // returns the client Account balance
}

b) Create a 20 element array that will be able to call the getClientBalance() method.

c) Assume Account instances in b); write statements that will sum the total balance of all Account in b)

5) Implement (code) the following method: public void fizzBuzzWoof (int N) { } that, given a positive integer N, prints the consecutive numbers from 1 to N, each on a separate line. However, any number divisible by 3, 5 or 7 should be replaced by the word Fizz, Buzz or Woof respectively . If a number is divisible by more than one of the numbers: 3, 5 or 7, it should be replaced by a concatenation of the respective words Fizz, Buzz and Woof in this given order. For example, numbers divisible by both 3 and 5 should be replaced by FizzBuzz and numbers divisible by all three numbers: 3, 5 and 7, should be replaced by FizzBuzzWoof. For example, here is the output for

N = 24:
1
2
Fizz
4
Buzz
Fizz
Woof
8
Fizz
Buzz
11
Fizz
13
Woof
FizzBuzz
16
17
Fizz
19
Buzz
FizzWoof
22
23
Fizz

5) Answer the following questions with the LinkedList definition defined below:

class LinkData {
public int num;
public LinkData next;
}

class LinkedListData {
private LinkData head;
LinkedListData ( ) { }
public int length( ) { // returns the number of elements in LinkedListData }
public void addLink (LinkData ld) { // add LinkData to the end of LinkedListData }
public void addLinkAt(int index, LinkData ld) { // add LinkData at index.
// Assume LinkedListData starts at index 0 }
public void removeFirst( ) { // remove the first node of LinkedListData
}

a) Implement (code) method length that will return the number of elements in LinkedListData.

b) Implement (code) method addLink that will add a LinkData to the end of LinkedListData

c) Implement (code) method addLinkAt that will add a LinkData to position specified in index

d) Implement (code) method removeFirst that will remove the first link in LinkedListData.

6) Answer the following questions below:

a) What is the difference between an array and ArrayList?

b) Define what is a Set, Map and List and the differences amongst a Set, Map and List.

c) Describe two ways to traverse through a Collection.

d) What is Queue and Stack? List their differences.

7) Use the following Collection API to answer the following questions:

Set< Object>: HashSet< Object>; TreeSet< Object>
List< Object>: ArrayList< Object>, LinkedList< Object>
Map< Object, Object>: HashMap< Object,Object>; TreeMap< Object,Object>

a) Given an array of characters, describe in pseudo code (high level algorithm) a process that will that will remove all duplicate characters.

EG:

char[] myChars = {‘a’,’e’,’b’,’s’,’t’,’v’,’a’,’s’,’f’,’b’,’a’};
removed duplicates: {‘a’,’e’,’b’,’s’,’t’,’v’,’f’}

b) Given an array of characters; describe in pseudo code (high level algorithm) a process that will print the characters that are duplicated (more than one).

EG:

char[] myChars = {‘a’,’e’,’b’,’s’,’t’,’v’,’a’,’s’,’f’,’b’,’a’};
Duplicate characters are: a, b, s
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.