Ask a question from expert

Ask now

Assignment on Programming Using Java

11 Pages2914 Words439 Views
   

Added on  2019-10-09

Assignment on Programming Using Java

   Added on 2019-10-09

BookmarkShareRelated Documents
Assignment 1Weight: 30% of your final gradeDue: after Unit 3This 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 thatname1 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
Assignment on Programming Using Java_1
AddressBookAttributes+ 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 skypeIdOperations+ 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. BonusOnSavingsAttributesOperations+ public double computeBonus(double commitment, double q1, double q2, double q3, double q4)Computer Science 268: Introduction to Programming (Java)Page 2 of 11
Assignment on Programming Using Java_2
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:1Elena Brandon34112Thomas Molson27323Hamilton Winn27854Suzie Sarandin32975Philip Winne44596Alex Trebok27537Emma Pivoto27548John Lenthen24319James Lean334110Jane Ostin412111Emily Car393412Daniel Hamshire299413Neda Bazdar343314Aaron Smith317615Kate Hen2658Computer Science 268: Introduction to Programming (Java)Page 3 of 11
Assignment on Programming Using Java_3
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.BanffMarathonRunnerAttributes+ private int time+ private int yearsOperations+ 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.417After the second month, the value in the account becomes (100 + 100.417) * (1 + 0.00417) = 201.252And 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
Assignment on Programming Using Java_4

End of preview

Want to access all the pages? Upload your documents or become a member.