CS 163/164, 🀨 Fall 2019 🀨
Lab 6 - Interfaces
Thursday, Sep. 12th or Friday, Sep. 13th
The purpose of this lab is to write Java code over the following topics:
- To create a program according to specifications
- To create a program using an interface.
- To understand iterative development.
1. Getting Started
- Create a new Java Project named Interfaces
- Copy L6if.java and Test.java into the project, make sure they are in the "src" folder.
- Create a class called Convert and have it implement L6if.
-
The TA will show you how to autogenerate method stubs from the interface and help you implement the first method toPounds.
- Write the methods in the interface according to the pre and
post conditions given below.
- In Test.java the first test case is given to you. Read the comment and create additional test cases so your output matches the comment.
- Show your code and output to the TA for credit.
2. Write the method body for toFahrenheit
- This method has the following properties:
- It is a public method, so "anyone" can call it.
- It returns a double value to the calling function.
- It takes one parameter of type double.
- Preconditions:
- The parameter is the temperature in Celsius.
- Postconditions:
- The return value is the temperature in Fahrenheit.
3. Write the method body for toASCII
- This method has the following properties:
- It is a public method, so "anyone" can call it.
- It returns an int value to the calling function.
- It takes one parameter of type char.
- Preconditions:
- The parameter is the character to convert to ASCII.
- Postconditions:
- The return value is the ASCII value of the character.
4. Write the method body for webify
- This method has the following properties:
- It is a public method, so "anyone" can call it.
- It returns an String value to the calling function.
- It takes one parameter of type String.
- Preconditions:
- The parameter is the string to put in web format.
- Postconditions:
- The return value is the web format of the string.
5. Write the method body for isEven
- This method has the following properties:
- It is a public method, so "anyone" can call it.
- It returns an boolean value to the calling function.
- It takes one parameter of type int.
- Preconditions:
- The parameter is the integer to check for "evenness".
- Postconditions:
- The return value is true if the parameter is even and false otherwise.
6. Write the remaining test cases in Test.java
- The comments in Test.java indicate we want your output to look like this:
- 22.046226218487757
- 68.0
- 65
- https://www.google.com
- false
- Follow the remaining comments in Test.java to write test cases for your methods.
Show your assignment to the TA for credit
© 2016 CS163/CS164 Colorado State University. All Rights Reserved.