Close Button
Signup/Login
Back All services Close Button

World's Leading Assignment Library

Continued assistance through writing and revision till final submission by the professional and experienced writers.

  • 10 subjects

  • 2,10,1000
    solved Questions

  • 500 Solved Questions
    Added Everyday

  • Download Solution
    in Seconds

PROGRAMMING AND DATA STRUCTURES

Question Preview:

Question B1
A fitness application has been written to allow people to log
exercise activities which they take, and identify their best
speeds over time. Some code has already been written for this
application, shown below.
public class Activity
{
private double duration; // in seconds
private double distance; // in kilometres
private String comment; // describe activity
public Activity(double t, double d, String w)
{
 duration = t;
 distance = d;
 comment = w;
}
/**...

View complete question »

Question Preview:

Question B1
A fitness application has been written to allow people to log
exercise activities which they take, and identify their best
speeds over time. Some code has already been written for this
application, shown below.
public class Activity
{
private double duration; // in seconds
private double distance; // in kilometres
private String comment; // describe activity
public Activity(double t, double d, String w)
{
 duration = t;
 distance = d;
 comment = w;
}
/**
 * get average speed for activity, in km/h
 */
public double averageSpeed()
{
 // to be completed
}
The class Activity records details of an individual fitness
event. The averageSpeed() method is incomplete.
a) Complete the body of the averageSpeed() method, to
calculate the average speed in kilometres per hour. Note
that seconds can be converted to hours by dividing by
3600. [4 marks]
[CSC8001]
Page 3 of 5
A separate class, Log, will maintain a list of Activity objects
together with the name of the person doing the activities. The
class has been partially written, as follows:
import java.util.ArrayList;
public class Log
{

 private String name;
 private ArrayList activities;
// constructor method to be completed

 public Activity bestSpeed()
 {
 Activity topAct;

 // find activity with highest speed

 return topAct;
 }
}
b) Write a constructor method for the Log class. New Log
objects should have a name initialised using a parameter to
the constructor method, and an empty list of activities.
[6 marks]
c) Write a method, addActivity, to class Log, to add a new
activity to the activities ArrayList. [4 marks]
[CSC8001]
Page 4 of 5
d) The bestSpeed()method will search all recorded
activities and return the activity with the highest average
speed. This method has been partially written in the class
declaration shown on the previous page. Complete the
body of the bestSpeed() method. [6 marks]
e) The activities list has the following type declaration:
private ArrayList activities;
Use of an ArrayList to store the Log entries may be a
problem if a large number of activities are to be recorded,
for example over the course of several years. Users of the
system have said they would like to be able to find an
activity using the date when the activity took place.
Suggest an alternative collection type that could be used to
store log entries, and access them by date (represented as
a String). Provide a type declaration for your chosen
collection type. [5 marks]
Question B2
The personnel management program at the University of Outer
Hebrides must handle information about the people employed
there. Employees may be on permanent or fixed-term
contracts. Write declarations for the following:
a) A class Employee, containing six fields specifying the
name, personnel number, address, designation (e.g.,
“lecturer”, “technician”, etc.), department and salary of the
person concerned (choose appropriate names and types).
Values for those state variables should be passed as
parameters to the class’s constructor. This class should
include appropriate accessor and mutator methods.
[6 marks]
[CSC8001]
Page 5 of 5
b) Classes Permanent and FixedTerm, which extend the
Employee class. Class Permanent adds a starting date of
an employee’s permanent contact (passed as a parameter
to the constructor). Class FixedTerm adds the duration of
a fixed term employee’s contract (passed as a parameter to
the constructor). [7 marks]
c) A method called z, which prints out the names of all
employees on permanent contracts in the department of
Zoology, and also prints out the total salary bill of that
department. The method should take as a parameter an
ArrayList, which contains Employee objects
representing all employees in the University. [12 marks]
END

View less »

Solution preview

Solution in attached zip file

Get solution

java assignment help

© Livewebtutors. All Rights Reserved 2018

Livewebtutors
Rated 4.9/5 based on 2480 reviews
Arrow up