ProductsLogo
LogoStudy Documents
LogoAI Grader
LogoAI Answer
LogoAI Code Checker
LogoPlagiarism Checker
LogoAI Paraphraser
LogoAI Quiz
LogoAI Detector
PricingBlogAbout Us
logo

Google Candidate Eligibility Checker

Verified

Added on  2019/10/09

|11
|2914
|439
Report
AI Summary
The assignment content involves programming tasks that require iterating through numbers, determining eligibility for positions based on regulatory abilities and average marks, and modifying a tax computation program to include new statuses and tax conditions.

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Assignment 1
Weight: 30% of your final grade
Due: after Unit 3
This assignment comprises ten questions. Each question is worth 10 marks. You are expected to
complete this assignment before you start Unit 4.
Upload your completed assignment to the Assignment 1 link on the course home page for marking and
tutor feedback.
Be sure to complete the final step—click on the Send for Marking button to notify your tutor.
Prerequisite: Read what an API is in the textbook Introduction to Programming Using Java by David J.
Eck on pages 142−143.
When solving the problems in this assignment, you must follow the application programming interface
(API) expected in each problem. You should implement all the attributes and operations mentioned in
the API.
Note that there is no main method in the APIs. That is, you should not perform any data processing
within the main method. You should rather use the main method to test other methods, prompt the
user for some inputs, and display the results returned by your methods.
1. Create a class named AddressBook that has the following field names:
firstName, middleName, lastName, homeAddress, businessPhone, homePhone,
cellphone, skypeId, facebookId, and personalWebSite.
Use appropriate data types to store the values for these fields in AddressBook objects.
Create appropriate get and set methods to retrieve and assign values to these names. For
example, getMiddleName(viveAddressBook) should return the middle name of the person
Vive. Similarly, vive.setPersonalWebsite(url) should set the personal website of the
person Vive to the specified URL object.
Using the get and set methods, create a comparison method compareNames(name1,
name2) that compares the first, middle, and last names of strings name1 and name2. Assume that
name1 and name2 follow the following format: “FirstName M. LastName”.
Test your program for correct, partially correct (e.g., name string without the middleName), and
incorrect inputs (e.g., phone number containing special characters).
Computer Science 268: Introduction to Programming (Java) Page 1 of 11

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Attributes
+ private String businessPhone
+ private String cellPhone
+ private String facebookId
+ private String firstName
+ private String homeAddress
+ private String homePhone
+ private String lastName
+ private String middleName
+ private String personalWebSite
+ private String skypeId
Operations
+ public AddressBook(String fn, String mn, String ln, String homeAddress, String businessPhone, String homePhone, String cellPhone, String skypeId, String facebookId, String personalWebSite)
+ public AddressBook(String fn)
+ public AddressBook(String fn, String mn)
+ public AddressBook(String fn, String mn, String ln)
+ public static String compareNames(String name1, String name2)
+ public String getBusinessPhone()
+ public String getCellPhone()
+ public String getFacebookId()
+ public String getFirstName()
+ public String getHomeAddress()
+ public String getHomePhone()
+ public String getLastName()
+ public String getMiddleName()
+ public String getPersonalWebSite()
+ public String getSkypeId()
+ public void setBusinessPhone(String businessPhone)
+ public void setCellPhone(String cellPhone)
+ public void setFacebookId(String facebookId)
+ public void setFirstName(String firstName)
+ public void setHomeAddress(String homeAddress)
+ public void setHomePhone(String homePhone)
+ public void setLastName(String lastName)
+ public void setMiddleName(String middleName)
+ public void setPersonalWebSite(String personalWebSite)
+ public void setSkypeId(String skypeId)
2. Space Inc. will give a quarterly and annual bonus to its employees only if the savings of the quarter
and/or the year are greater than or equal to quarterly minimum (monthly commitment x 3) and/or
the annual minimum (monthly commitment x 12) amount, respectively. The quarterly bonus is 3%
of eligible quarterly savings, and the annual bonus is 5% of annual savings if eligible. If the annual
savings exceeds the committed amount by at least 25%, Space Inc. matches the additional savings
(25% or above) as part of the annual bonus.
I. An employee has committed to save $2000 per month. Her quarterly savings are as follows:
Q1 – $5000, Q2 – $7000, Q3 – $4000, and Q4 – $8000.
II. Another employee has committed to save $3000 per month. His quarterly savings are as follows:
Q1 – $6000, Q2 – $9000, Q3 – $10000, and Q4 – $17000.
Write a program to compute the total bonus amount earned by these two employees in the year.
Attributes
Operations
+ public double computeBonus(double commitment, double q1, double q2, double q3, double q4)
Computer Science 268: Introduction to Programming (Java) Page 2 of 11
Document Page
3. Write a program that prompts the user to enter two points (x1, y1) and (x2, y2). Calculate and
display the distance between the two points using the formula below. Round the answer up to 2
decimal points. You can use Math.pow(a,0.5) to compute the square root of an expression.
Math.pow() returns a double.
For example, the distance between the points (−2, −3) and (−4, 4) is approximately 7.28, as shown
below.
4. A group of AU friends decide to run the Banff, Alberta, Marathon. Their names, times (marathon
completion time in minutes), and number of years participated are given below:
1 Elena Brandon 341 1
2 Thomas Molson 273 2
3 Hamilton Winn 278 5
4 Suzie Sarandin 329 7
5 Philip Winne 445 9
6 Alex Trebok 275 3
7 Emma Pivoto 275 4
8 John Lenthen 243 1
9 James Lean 334 1
10 Jane Ostin 412 1
11 Emily Car 393 4
12 Daniel Hamshire 299 4
13 Neda Bazdar 343 3
14 Aaron Smith 317 6
15 Kate Hen 265 8
Computer Science 268: Introduction to Programming (Java) Page 3 of 11
Document Page
Extend the AddressBook class from Problem 1 to store the additional data. Now, write a method
to find the fastest runner. Print the name, address, and his/her time (in minutes) on three separate
lines.
Find the second fastest runner. Print the name, address, his/her time (in minutes), and the
difference in time with the fastest runner.
Compute the average time of completion taken by these runners.
Finally, print the name and number of years participated for each runner if the runner’s time of
completion is equal to or better than the average time of completion.
Attributes
+ private int time
+ private int years
Operations
+ public BanffMarathonRunner(String fn, String ln, int min, int yr)
+ public int getTime()
+ public int getYears()
+ public static BanffMarathonRunner getFastestRunner(BanffMarathonRunner[] runners)
+ public static BanffMarathonRunner getSecondFastestRunner(BanffMarathonRunner[] runners)
+ public static double getAverageTime(BanffMarathonRunner[] runners)
+ public static String getAboveAverageRunners(BanffMarathonRunner[] runners)
+ public void setTime(int time)
+ public void setYears(int years)
5. Solve the following problem using a program: Suppose you save $100 each month into a savings
account with an annual interest rate of 5%. Thus, the monthly interest rate is 0.05/12 = 0.00417.
After the first month, the value in the account becomes 100 * (1 + 0.00417) = 100.417
After the second month, the value in the account becomes (100 + 100.417) * (1 + 0.00417) =
201.252
And after the third month, the value in the account becomes (100 + 201.252) * (1 + 0.00417) =
302.507
and so on.
Write a program that randomly generates monthly savings amounts for the 15 runners in Problem 4.
Each monthly saving should be in the range of $100 to $800. Extend the AddressBook class to
store the monthly savings generated by the random number generator.
Then, display the final account value for each of the 15 runners.
Computer Science 268: Introduction to Programming (Java) Page 4 of 11

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Attributes
+ private double accountValue
+ private double[] monthlyInterests
+ private double[] monthlySavings
+ public static final double ANNUAL_INTEREST_RATE
Operations
+ public double getAccountValue()
+ public double[] calculateInterests()
+ public double[] generateMonthlySavings()
+ public double[] getMonthlyInterests()
+ public double[] getMonthlySavings()
+ public EmployeeSavings(String fn, String ln)
+ public EmployeeSavings(String fn, String ln, double[] d1, double[] d2)
+ public static String getReport(EmployeeSavings[] arr)
6. “The Pythagorean Theorem relates the lengths of the three sides of any right triangle. The legs of a
right triangle (the two sides of the triangle that meet at the right angle) are customarily labelled as
having lengths “a” and “b”, and the hypotenuse (the long side of the triangle, opposite the right
angle) is labelled as having length “c”. The lengths are related by the following equation: a ^2 + b^2
= c ^2.” – refer to http://www.purplemath.com/modules/pythagthm.htm for details.
This equation allows you to find the length of a side of a right triangle when they’ve given you the
lengths for the other two sides, and, going in the other direction, allows you to determine if a
triangle is a right triangle when they’ve given you the lengths for all three sides.
This equation can alternatively be written as c = sqrt of (a^2+b^2). You can find the square root of a
number by calling the standard function Math.sqrt. For example, the statement double y =
Math.sqrt(x) sets y to the square root of x.
I. Given the right triangles described below, write a program to compute the lengths of the
remaining sides using a program.
a. a = 48 and c = 80
b. a = 84 and c = 91
II. Determine if the following triangles are right-angled triangles:
a. a = 45, b = 55, and c = 75
b. a = 28, b = 45, and c = 53
Computer Science 268: Introduction to Programming (Java) Page 5 of 11
Document Page
7. Douglas Hofstadter’s Pulitzer-prize-winning book Gödel, Escher, Bach contains many interesting
mathematical puzzles. In Chapter XII, Hofstadter mentions a wonderful problem that is well within
the scope of the control statements in Java. The problem can be expressed as follows: Pick some
positive integer and call it n. If n is even, divide it by two. If n is odd, multiply it by three and add
one. Continue this process until n is equal to 1. Hofstadter illustrates this process with the following
example, starting with the number n = 15:
15 is odd, so I make 3n+1: 46
46 is even, so I take half: 23
23 is odd, so I make 3n+1: 70
70 is even, so I take half: 35
35 is odd, so I make 3n+1: 106
106 is even, so I take half: 53
53 is odd, so I make 3n+1: 160
160 is even, so I take half: 80
80 is even, so I take half: 40
40 is even, so I take half: 20
20 is even, so I take half: 10
10 is even, so I take half: 5
5 is odd, so I make 3n+1: 16
16 is even, so I take half: 8
8 is even, so I take half: 4
4 is even, so I take half: 2
2 is even, so I take half: 1
As you can see from this example, the numbers go up and down, but eventually—at least for all
numbers that have ever been tried—come down to end in 1. In some respects, this process is
reminiscent of the formation of hailstones, which get carried upward by the winds over and over
Computer Science 268: Introduction to Programming (Java) Page 6 of 11
Document Page
again before they finally descend to the ground. Because of this analogy, this sequence of numbers
is usually called the Hailstone sequence, although it goes by many other names as well.
Write a program that reads in a number from the user and then displays the Hailstone sequence for
that number, followed by a line showing the number of steps taken to reach 1.
Attributes
Operations
+ public static ArrayList<Integer> getHailstoneSequence(int n)
8. Google Inc. is looking to recruit three of the Boston runners. The criteria for selection are as follows:
I. Average final marks in bachelor’s degree (store up to 2 decimal places). The fifteen candidates
have the following grades: 82.30%, 85.10%, 77.77%, 69.93%, 93.03%, 88.61%, 55.99%, 87.49%,
88.00%, 91.20%, 66.79%, 76.65%, 55.89%, 90.01%, and 87.9%.
II. Ability to communicate as one of the three values – “excellent”, “average”, and “poor”. The
fifteen candidates have the following ability to communicate, respectively: poor, poor, average,
average, average, poor, excellent, excellent, excellent, average, excellent, average, excellent,
excellent, poor.
III. Innovation as one of the two values – “brilliant” and “average” (store as a Boolean; brilliant =
true and average = false). The fifteen candidates have the following innovative abilities: brilliant,
average, average, average, brilliant, brilliant, average, brilliant, average, brilliant, average,
brilliant, brilliant, average, average.
IV. Ability to regulate one’s own skill as a probability value between 0 and 1.0 – 1.0 implies
excellent regulatory capabilities and 0.0 implies no skills to regulate (store as a double). The
fifteen candidates have the following regulatory abilities: 0.5, 1.0, 0.8, 0.0, 1.0, 0.7, 0.8, 0,9, 0.5,
0.6, 0.3, 0.2, 0.5, 0.3, 0.8.
Store these values for the fifteen candidates in an extended AddressBook class. In general,
Google will not consider a candidate with average marks of less than 85%. Google will consider a
candidate with average marks of less than 85% only if the candidate at least has 0.5 regulatory
abilities and at least ‘average’ ability to communicate. Google will only consider a candidate with
poor communication ability if the candidate has a ‘brilliant’ innovation capability. Write a program
that will help Google to programmatically determine eligibility of the fifteen candidates for these
positions, and print the output on the console.
Computer Science 268: Introduction to Programming (Java) Page 7 of 11

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
9. Write a program that iterates through numbers from 0 to 113 using a loop. Print the numbers, one
number per line. As you print each number, say x, also print the following when appropriate,
separated by commas:
I. If the number is odd, print “x is odd”
II. If the number is divisible by 5, print “hi five”
III. If the total of a number (x) and its subsequent number (x+1) is a value divisible by 7, print “wow”
IV. If the number is prime, print “prime”.
Attributes
Operations
+ public static ArrayList<String> iterate()
+ public static boolean isDivisibleBy5(int n)
+ public static boolean isDivisibleBy7(int n)
+ public static boolean isOdd(int n)
+ public static boolean isPrime(int n)
Computer Science 268: Introduction to Programming (Java) Page 8 of 11
Document Page
10. Modify the following program to the specifications given below:
I. Add a new status – SingleParent – where the tax is computed as a SINGLE but with a
further reduction of $5000 per child.
II. Add a new tax condition – if the income is greater than $249,999 for SINGLE, then add a tax of
25% on income amount above $150,000; if the income is greater than $349,999 for MARRIED,
then add a tax of 35% on income amount above $200,000.
III. Unknown status – if the status doesn’t belong to SINGLE or MARRIED or SINGLE_PARENT, then
compute a 33% tax on the income.
import java.util.Scanner;
public class TaxReturn
{
/**
Constructs a TaxReturn object for a given income and
marital status, and computes the tax.
@param anIncome the taxpayer income
@param aStatus either SINGLE or MARRIED
*/
public TaxReturn(double anIncome, int aStatus)
{
income = anIncome;
status = aStatus;
}
public double getTax()
{
double tax = 0;
if (status == SINGLE)
{
if (income <= SINGLE_BRACKET1)
tax = RATE1 * income;
else if (income <= SINGLE_BRACKET2)
tax = RATE1 * SINGLE_BRACKET1
+ RATE2 * (income - SINGLE_BRACKET1);
else
tax = RATE1 * SINGLE_BRACKET1
+ RATE2 * (SINGLE_BRACKET2 - SINGLE_BRACKET1)
+ RATE3 * (income - SINGLE_BRACKET2);
}
else
{
if (income <= MARRIED_BRACKET1)
tax = RATE1 * income;
else if (income <= MARRIED_BRACKET2)
Computer Science 268: Introduction to Programming (Java) Page 9 of 11
Document Page
tax = RATE1 * MARRIED_BRACKET1
+ RATE2 * (income - MARRIED_BRACKET1);
else
tax = RATE1 * MARRIED_BRACKET1
+ RATE2 * (MARRIED_BRACKET2 - MARRIED_BRACKET1)
+ RATE3 * (income - MARRIED_BRACKET2);
}
return tax;
}
public static final int SINGLE = 1;
public static final int MARRIED = 2;
private static final double RATE1 = 0.15;
private static final double RATE2 = 0.28;
private static final double RATE3 = 0.31;
private static final double SINGLE_BRACKET1 = 21450;
private static final double SINGLE_BRACKET2 = 51900;
private static final double MARRIED_BRACKET1 = 35800;
private static final double MARRIED_BRACKET2 = 86500;
private double income;
private int status;
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter your income: ");
double income = in.nextDouble();
System.out.print("Enter S (single) or M (married): ");
String input = in.next();
int status = 0;
if (input.equalsIgnoreCase("S"))
status = TaxReturn.SINGLE;
else if (input.equalsIgnoreCase("M"))
status = TaxReturn.MARRIED;
else
{
System.out.println("Bad input.");
return;
}
TaxReturn aTaxReturn = new TaxReturn(income, status);
System.out.println("The tax is " + aTaxReturn.getTax());
}
}
Computer Science 268: Introduction to Programming (Java) Page 10 of 11

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Attributes
+ private double income
+ private int children
+ private int status
+ private static final double CHILDREN_REDUCTION
+ private static final double MARRIED_BRACKET1
+ private static final double MARRIED_BRACKET2
+ private static final double MARRIED_BRACKET3
+ private static final double MARRIED_BRACKET4
+ private static final double RATE1
+ private static final double RATE2
+ private static final double RATE3
+ private static final double RATE4
+ private static final double RATE5
+ private static final double RATE6
+ private static final double SINGLE_BRACKET1
+ private static final double SINGLE_BRACKET2
+ private static final double SINGLE_BRACKET3
+ private static final double SINGLE_BRACKET4
+ public static final int MARRIED
+ public static final int SINGLE
+ public static final int SINGLE_PARENT
+ public static final int UNKNOWN
Operations
+ public double getTax()
+ public TaxReturn(double anIncome, int aStatus, int children)
Computer Science 268: Introduction to Programming (Java) Page 11 of 11
1 out of 11
[object Object]

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]