Assignment on Programming Using Java

Added on - 09 Oct 2019

Trusted by +2 million users,
assist thousands of students everyday
Showing pages 1 to 4 of 11 pages
Assignment 1Weight: 30% of your final gradeDue: after Unit 3This assignment comprises ten questions. Each question is worth 10 marks. You are expected tocomplete this assignment before you start Unit 4.Upload your completed assignment to the Assignment 1 link on the course home page for marking andtutor feedback.Be sure to complete the final step—click on theSend for Markingbutton to notify your tutor.Prerequisite:Read what an API is in the textbookIntroduction to Programming Using Javaby 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 theattributesandoperationsmentioned inthe API.Note that there is nomainmethod in the APIs. That is, you should not perform any data processingwithin themainmethod. You should rather use themainmethod to test other methods, prompt theuser for some inputs, and display the results returned by your methods.1.Create a class namedAddressBookthat has the following field names:firstName,middleName,lastName,homeAddress,businessPhone,homePhone,cellphone,skypeId,facebookId, andpersonalWebSite.Use appropriate data types to store the values for these fields inAddressBookobjects.Create appropriategetandsetmethods to retrieve and assign values to these names. Forexample,getMiddleName(viveAddressBook)should return the middle name of the personVive. Similarly,vive.setPersonalWebsite(url)should set the personal website of theperson Vive to the specified URL object.Using thegetandsetmethods, create a comparison methodcompareNames(name1,name2)that compares the first, middle, and last names of stringsname1andname2. Assume thatname1andname2follow the following format: “FirstName M. LastName”.Test your program for correct, partially correct (e.g., name string without themiddleName), andincorrect inputs (e.g., phone number containing special characters).Computer Science 268: Introduction to Programming (Java)Page1of11
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 quarterand/or the year are greater than or equal to quarterly minimum (monthly commitmentx3) and/orthe annual minimum (monthly commitmentx12) amount, respectively. The quarterly bonus is 3%of eligible quarterly savings, and the annual bonus is 5% of annual savings if eligible. If the annualsavings 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)Page2of11
3.Write a program that prompts the user to enter two points (x1, y1) and (x2, y2). Calculate anddisplay the distance between the two points using the formula below. Round the answer up to 2decimal points. You can useMath.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 shownbelow.4.A group of AU friends decide to run the Banff, Alberta, Marathon. Their names, times (marathoncompletion 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)Page3of11
Extend theAddressBookclass from Problem 1 to store the additional data. Now, write a methodto find the fastest runner. Print the name, address, and his/her time (in minutes) on three separatelines.Find the second fastest runner. Print the name, address, his/her time (in minutes), and thedifference 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 ofcompletion 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 savingsaccount 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 theAddressBookclass tostore 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)Page4of11
You’re reading a preview
Preview Documents

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document