Starting from:

$30

CSC221 Assignment 1 – Solved

Assignment 1 –

How to submit: upload JAVA files to Blackboard

How many steps in a mile? 

A steps‐to‐miles calculator determines the distance a person should walk in order to attain a specific number of steps. The formula is specific to every person and should be based on the length of their stride. A person’s stride is calculated based on their gender, height, and whether they are walking or running.

For this assignment we will implement a very simple walking steps to miles calculator using the formulas provided next.

Disclaimer: this assignment is only meant as a programming assignment and is not meant for any other purposes. Note:  

ü  this is an individual assignment; please do your own work, sharing and/or copying code and/or solution ideas with/from others will result in a grade of 0 and disciplinary actions for all involved parties. If you run into problems and have done your best to solve them, please contact me before/after class or by e-mail. 

ü  A 20% grade deduction for every day the assignment is late. 

Assignment’s Requirements: 

1.     Program should compile and run in order to be graded

2.     You must use 𝑆𝑡𝑟𝑖𝑛𝑔 𝑓𝑜𝑟𝑚𝑎𝑡𝑡𝑒𝑟𝑠 𝑖. 𝑒. 𝑝𝑟𝑖𝑛𝑡𝑓 … for ALL output statements. Your solution should NOT contain the methods 𝑝𝑟𝑖𝑛𝑡 OR 𝑝𝑟𝑖𝑛𝑡𝑙𝑛 .

3.     You should not need any 3rd party libraries (i.e. libraries besides Java’s API). If you think some libraries maybe useful, please check with me first.

4.     Comment your code:

a.     Javadoc comments for the class

b.     Javadoc comments for each of the class’ members (variables and methods)

c.      Comments for major steps in your code

5.     Submit two separate classes each in its own JAVA file. Please use Blackboard’s upload feature and don’t submit your compiled code or LINKS to online editors.

a.     𝑆𝑡𝑒𝑝𝑠𝑇𝑜𝑀𝑖𝑙𝑒𝑠 – a container and operations class for the calculator. Follow the names shown in the UML diagram in Figure 1 exactly. I use a test script to examine your code which fails if you do not follow the naming convention.

b.     𝑇𝑒𝑠𝑡𝑆𝑡𝑒𝑝𝑠𝑇𝑜𝑀𝑖𝑙𝑒𝑠 – This class contains the main method to perform unit testing on the previous class.

Class 𝑺𝒕𝒆𝒑𝒔𝑻𝒐𝑴𝒊𝒍𝒆𝒔: 

a.     Four variables: 𝑛𝑎𝑚𝑒 (String), 𝑓𝑒𝑒𝑡 (double), and 𝑖𝑛𝑐ℎ𝑒𝑠 (double).

b.     Default 𝑐𝑜𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑜𝑟 to initialize the variables to their default values – null for strings and ‐1 for numeric.

c.     𝑁𝑜𝑛                  𝑑𝑒𝑓𝑎𝑢𝑙𝑡 constructor to initialize the variables using the constructor’s parameters.

d.     𝐴𝑐𝑐𝑒𝑠𝑠𝑜𝑟𝑠 (setters) and 𝑚𝑢𝑡𝑎𝑡𝑜𝑟𝑠 (getters) methods for all four variables – 6 methods in total.

e.     ℎ𝑒𝑖𝑔ℎ𝑡_𝑖𝑛𝑐ℎ𝑒𝑠             returns the height in inches. Conversion: 1𝑓𝑡        12 𝑖𝑛𝑐ℎ𝑒𝑠

f.      𝑠𝑡𝑟𝑖𝑑𝑒𝐿𝑒𝑛𝑔𝑡ℎ_𝑖𝑛𝑐ℎ𝑒𝑠              returns the length of a person’s stride. Remember to invoke the previous method:

ð  𝑠𝑡𝑟𝑖𝑑𝑒             ≪ ℎ𝑒𝑖𝑔ℎ𝑡_𝑖𝑛𝑐ℎ𝑒𝑠 ≫        0.413

g.     𝑚𝑖𝑙𝑒𝑠 𝑠𝑡𝑒𝑝𝑠 returns the number of miles to walk given the desired number of steps. Remember to invoke the previous methods:

ð  𝑚𝑖𝑙𝑒𝑠                

h.     𝑐𝑢𝑟𝑟𝐷𝑎𝑡𝑒 returns today’s date as a String. One way is to use Java’s 𝐺𝑟𝑒𝑔𝑜𝑟𝑖𝑎𝑛𝐶𝑎𝑙𝑒𝑛𝑑𝑎𝑟 to first extract the 𝑀𝑜𝑛𝑡ℎ, 𝐷𝑎𝑦, 𝑌𝑒𝑎𝑟 values, then build a string representing today’s date. https://docs.oracle.com/javase/8/docs/api/java/util/GregorianCalendar.html)

i.      𝑓𝑜𝑟𝑚𝑎𝑡𝐴𝑠𝑆𝑡𝑟𝑖𝑛𝑔: receives one input for the numbers of steps and formats and returns the class’ members as a multi‐line string. Use the String format method to format and return the values as shown in Figure 2.

ü  All leading labels should have column widths of 13 characters

ü  All floating‐point numbers have precision 2 and the thousands comma (i.e. decimal separator)

Class 𝑻𝒆𝒔𝒕𝑺𝒕𝒆𝒑𝒔𝑻𝒐𝑴𝒊𝒍𝒆𝒔: 

ü  Remember to show a message string before each prompt and use 𝑝𝑟𝑖𝑛𝑡𝑓        ONLY

a.     Create an instance of class 𝑆𝑡𝑒𝑝𝑠𝑇𝑜𝑀𝑖𝑙𝑒𝑠 using the 𝑑𝑒𝑓𝑎𝑢𝑙𝑡 constructor. Use the mutator methods to assign values to the class’ private members. See Figure 2 for a sample test.

b.     Prompt the user to enter a 𝑛𝑎𝑚𝑒 and ℎ𝑒𝑖𝑔ℎ𝑡 in 𝑓𝑒𝑒𝑡 and 𝑖𝑛𝑐ℎ𝑒𝑠. See Figure 2 for a sample test. These values will be used in the next step.

c.     Create a second instance of 𝑆𝑡𝑒𝑝𝑠𝑇𝑜𝑀𝑖𝑙𝑒𝑠 using the non‐default constructor. Use the values entered in the previous step.

d.     Using 𝑝𝑟𝑖𝑛𝑡𝑓                :

1.     Using the 1st instance, print today’s as shown in Figure 2

pass the value 12345
2.     Using the 1st instance, print the results of calling the function 𝑓𝑜𝑟𝑚𝑎𝑡𝐴𝑠𝑆𝑡𝑟𝑖𝑛𝑔,  for the steps parameter.

pass the value 1000
3.     Using the 2nd instance, print the results of calling the function 𝑓𝑜𝑟𝑚𝑎𝑡𝐴𝑠𝑆𝑡𝑟𝑖𝑛𝑔,  for the steps parameter.

Grading: 

Item 
Points 
Comments (Javadoc and major steps)
10
𝑃𝑒𝑟𝑠𝑜𝑛𝑊𝑒𝑖𝑔ℎ𝑡 class (Compiles and runs)
 
3 variables
3
Accessor and mutator methods
6
2 Constructors
10
      ℎ𝑒𝑖𝑔𝑡ℎ_𝐼𝑛𝑐ℎ𝑒𝑠          
5
      𝑠𝑡𝑟𝑖𝑑𝑒𝐿𝑒𝑛𝑔𝑡ℎ_𝐼𝑛𝑐ℎ𝑒𝑠          
5
      𝑚𝑖𝑙𝑒𝑠          
5
𝑇𝑒𝑠𝑡𝑃𝑒𝑟𝑠𝑜𝑛𝑊𝑒𝑖𝑔ℎ𝑡 class (Compiles and runs)
 
Prompts
10
1st instance using default constructor
5
2nd instance using default constructor
10
Today’s date
5
𝑝𝑟𝑖𝑛𝑡𝑓
16
Correct output
10
 
100 
Figures: 

  

Figure 1: Class Diagram – UML legend shown below  

ç  Prompts for the 2nd instance. Prompts are right aligned 

ç Today’s date. Label is right aligned 

ç Formatted output of the 1st instance which used the default constructor and hard‐coded values. Labels are right aligned 

 

ç Formatted output of the 2nd instance which used the non‐default constructor and the prompted values above. Labels are right aligned 

 

Figure 2: Sample Run 

 

 

 

UML Diagram Legend 

Symbol 
Description 
  
A private member (i.e. variable or method) 
  
A private final member (i.e. variable) 
  
A public field (i.e. variable or method) 
  
A public abstract member (i.e. variable or method) 
  
A public constructor 
  
A static public member 
  
An interface 
  
A public class 
  
A public abstract class 
  
A hollowed arrow indicates inheritance 
  
An open-ended arrow indicates composition 
  
A dotted line and hollowed arrow indicate class implementation 
 

 

More products