You are on page 1of 8

COSC1336 Programming Fundamentals I / ITSE1302 Computer Programming

The submission opens two days before the due day, and closes right at the due time. It is students' responsibility to submit
timely and correctly in order to get credits. Students MUST start each project when it is first discussed in class in order to
complete it on time. All projects are individual projects. Each submission must include all required documents. The last
submission will be graded. Project due days may be changed to better align with lectures.
If one of the following is true, no credits will be given:
The project is late.
The algorithm of the main method is missing or the class design is missing.
Wrong files are submitted or part of the source codes is submitted.
The project has errors.
The comments are not complete.
The project is a copy and modification of another students project. (Both will receive 0.)
Software Development General Project Rubric: (Design is worth 20%; the rest is worth 80 %.)
Analysis: There will be no credit if the software doesnt meet customer specification at all.
Does the software meet the exact customer specification?
Does the software read the exact input data and display the exact output data as they are shown in sample runs?
Does each class include all corresponding data and functionalities?
Design: There will be no credit if the design is missing.
Is the main method algorithm an efficient solution?
Does the main method algorithm convert the input data into desired output data efficiently?
Is the design (a UML class diagram) an efficient solution?
Is the design created correctly?
Code: There will be no credit if there are errors.
Are there errors in the software?
Are code conventions and name conventions followed?
Does the software use the minimum computer resource (computer memory and processing time)?
Is the software reusable?
Debug:
Are there bugs in the software?
Documentation: There will be no credit if comments are not included.
Class comments must be included in Javadoc format before a class header.
Method comments must be included in Javadoc format before a method header.
More inline comments must be included in either single line format or block format inside each method body.
All comments must be complete in correct format.

The above five activities are explained in more


details next. Project description starts at page 7.
The following incudes, NOT LIMITED TO, a list of things you need to do/check for each project. In addition to this,
guidelines discussed in class must be enforced in each project. Examples included in this document are for demonstration
purpose, and they may not be related to this project.
1

Analysis:
Software must be made to meet all customer requirements/specifications. These include how input should be entered, how
output should be displayed in a user interface. The values for input and output may be changed, but descriptions for each
value are the same.
For example, in the user interface below, a user-entered temperature in Fahrenheit (32), and the equivalent temperature in
Celsius (0) can be changed, but their descriptions (highlighted text) are always the same. Sometimes a value is required to
be entered or displayed on the same line as the description or on a new line. Sometimes, additional descriptions are
required. In this case, a user-entered value (input) is required to be entered on the same line as the description. The
desired out value (a temperature in Celsius) is required to be displayed on a new line.
Enter a temperature in Fahrenheit: 32
This is equivalent to:
0 Celsius
Design:
A most efficient solution must be designed. A solution is written as an algorithm. An algorithm has four parts: summary,
input, processing, and output. Summary includes a brief description of the algorithm. Input specifies user-entered input
values in order. Processing specifies how user-entered input values are converted into desired output values. Output
specifies output values in order. Descriptions of each value are added into a Java source file ONLY.
For example,
Algorithm: (A normal text file)
Summary
Covert a temperature from Fahrenheit to Celsius.
Input:
Input
Read a temperature in Fahrenheit entered via keyboard.
Processing
Processing:
Convert the temperature from Fahrenheit to Celsius by deducting 32, and then multiplying the
result by 5, and then dividing the result by 9.
Output:
Output
Display the converted temperature in Celsius.
An algorithm is a logical series of steps of a solution that solves a problem. Use English phrases/words ONLY. Dont
use programing specific symbols or programming syntax. An algorithm must specify each steps with details. An
algorithm should not contain redundant steps or any steps that dont contribute to a most efficient solution. The following
shows a few bad examples.
Descriptions of a value is added in Java Source file ONLY.
Bad example 1:
Input:
Display Enter a temperature in Fahrenheit:.
Memory reservation is added in Java
Declare a variable called temperature.
Source file ONLY.
Read a temperature in Fahrenheit entered via keyboard.
Bad example 2:
Processing:
Convert a temperature from Fahrenheit to Celsius.
Bad example 3:
Processing:
Convert the temperature from Fahrenheit to Celsius:
C = (F 32) * 5 / 9

It is not detailed. It doesnt state how to convert


a temperature from Fahrenheit to Celsius.

* and / are programing specific symbols or


programming syntax. Use English ONLY.
2

Bad example 4:
Output:
Display This is equivalent to:
Display the converted temperature in Celsius.
Display Celsius.

Descriptions of a value is added in Java Source


file ONLY.

Code:
A Java source file can contain a class. It is the translation of an algorithm written in programming syntax.
Each class is made up of the following components:
import statements if any
Javadoc class comments right before class header. The open brace { of the class body must be at the end of the
header.
Javadoc method comments right before method header. The open brace { of the method body must be at the end
of the header.
Class comments must be included in Javadoc
Import statements if any
format before a class header. A description of

the class, author information and version


import java.util.Scanner;
import java.text.DecimalFormat;
information are required.
/**
* Reads a temperature in Fahrenheit, and converts it to a temperature in Celsius.
* @author Qi Wang
Method comments must be included in Javadoc format
* @version 1.0
Open {
*/
before a method header. A description of the class,
public class TempConverter{
parameter information, and return type information are
/**
required.
* Reads a temperature in Fahrenheit entered via keyboard, and
* converts it to a temperature in Celsius by:
Class
* - subtracting 32 from Fahrenheit temperature,
header
* - multiplying the result by 5, and
Class
* - dividing the result by 9
body
* @param args A reference to a string array containing command-line arguments
*/
Open {
public static void main(String[] args){
at the
final int BASE = 32;
final double CONVERSION_FACTOR = 5.0 / 9.0;
double celsiusTemp, fahrenheitTemp;
Method
Method
Scanner scan = new Scanner(System.in);
body
header
DecimalFormat temperatureFormat = new DecimalFormat("0.00");
// Read a temperature in Fahrenheit entered via keyboard.
System.out.print ("Enter a Fahrenheit temperature: ");
fahrenheitTemp = scan.nextDouble();
// Convert the temperature from Fahrenheit to Celsius
// by deducting 32, and then multiplying the result by 5,
//and then dividing the result by 9.
celsiusTemp = CONVERSION_FACTOR * (fahrenheitTemp - BASE);
// Display the converted temperature in Celsius.
System.out.println ("Celsius Equivalent: " +
temperatureFormat.format(celsiusTemp));
}
}

Source code: (A Java source file)

import java.util.Scanner;

Inside the method main, input, processing, and import java.text.DecimalFormat;


output of an algorithm are copied as single line /**
comments. They are the only comments needed * Reads a temperature in Fahrenheit, and converts it to a temperature in Celsius.
for method main. Each steps is translated into
* @author Qi Wang
programming syntax. Memory reservations are * @version 1.0
included at the beginning of the method. Please */
public class TempConverter{
see next example.

Create a temperature converter application to convert


from Fahrenheit to Celsius. Read the Fahrenheit
temperature from the user.

Algorithm: (A normal text file)

Summary

Covert a temperature from Fahrenheit to Celsius.


Input
Input:
Read a temperature in Fahrenheit entered via
keyboard.
Processing:
Convert the temperature from Fahrenheit to Celsius
by deducting 32, and then multiplying the result by 5,
and then dividing the result by 9.
Processing
Output:
Display the converted temperature in Celsius.

/**
* Reads a temperature in Fahrenheit entered via keyboard, and
* converts it to a temperature in Celsius by:
* - subtracting 32 from Fahrenheit temperature,
* - multiplying the result by 5, and
* - dividing the result by 9
* @param args A reference to a string array containing
*
command-line arguments
*/
public static void main(String[] args){
final int BASE = 32;
final double CONVERSION_FACTOR = 5.0 / 9.0;
Memory
double celsiusTemp, fahrenheitTemp;
Reservation
Scanner scan = new Scanner(System.in);
DecimalFormat temperatureFormat = new DecimalFormat("0.00");
// Read a temperature in Fahrenheit entered via keyboard.
System.out.print ("Enter a Fahrenheit temperature: ");
fahrenheitTemp = scan.nextDouble();

Output

Input

// Convert the temperature from Fahrenheit to Celsius


// by deducting 32, and then multiplying the result by 5,
//and then dividing the result by 9.
celsiusTemp = CONVERSION_FACTOR * (fahrenheitTemp - BASE);

Processing

// Display the converted temperature in Celsius.


System.out.println ("Celsius Equivalent: " +
temperatureFormat.format(celsiusTemp));

Output

}
}

To enforce program readability, consistent indentations must be used to show containment hierarchy. Readability is very
important. Poor readability of a source file can be ignored or misinterpreted. This will definitely affect a software
developers performance. Please read the following, and careful exam your source file.
1. Align Javadoc comments with its source codes.
2. Use consistent indentations to enhance readability:
Indent inside the body of a class
Indent again in the body of each method of this class
Indent again in each block statement of each method.
3. Use required spaces, not excess spaces to enhance readability:
No spaces between comments and the corresponding method header.
One space after * at the beginning of each line in Javadoc comments.
Align first * of each line in Javadoc comments.
One space in between two adjacent variables.
One line in between two sections of codes.
import java.util.Scanner;
import java.text.DecimalFormat;
/**
* Reads a temperature in Fahrenheit, and converts it to a temperature in Celsius.
* @author Qi Wang
* @version 1.0
*/
public class TempConverter{
/**
TAB
* Reads a temperature in Fahrenheit entered via keyboard, and
* converts it to a temperature in Celsius by:
* - subtracting 32 from Fahrenheit temperature,
TAB
* - multiplying the result by 5, and
* - dividing the result by 9
* @param args A reference to a string array containing
TAB
*
command-line arguments
*/
TAB
public static void main(String[] args){
final int BASE = 32;
TAB
TAB
final double CONVERSION_FACTOR = 5.0 / 9.0;
double celsiusTemp, fahrenheitTemp;
Scanner scan = new Scanner(System.in);
TAB
TAB
DecimalFormat temperatureFormat = new DecimalFormat("0.00");
TAB

TAB

TAB

TAB

TAB

TAB

TAB

TAB

// Read a temperature in Fahrenheit entered via keyboard.


System.out.print ("Enter a Fahrenheit temperature: ");
fahrenheitTemp = scan.nextDouble();
// Convert the temperature from Fahrenheit to Celsius
// by deducting 32, and then multiplying the result by 5,
//and then dividing the result by 9.
celsiusTemp = CONVERSION_FACTOR * (fahrenheitTemp - BASE);
// Display the converted temperature in Celsius.
System.out.println ("Celsius Equivalent: " +
temperatureFormat.format(celsiusTemp));

}
}

Coding conventions (posted in Canvas)are a set of guidelines for a specific programming language that recommend
programming style, practices and methods for each aspect of a piece program written in this language. These conventions
usually cover file organization, indentation, comments, declarations, statements, white space, naming conventions,
programming practices, programming principles, programming rules of thumb, architectural best practices, etc.
By convention,
A variable name usually starts with a lowercase letter with each of the additional words capitalized.
A class name is usually a singular capitalized singular noun with each word capitalized.
A constant should be defined as a final variable, and should be written in ALL_CAP with an underscore in
between two adjacent words. For example,
final double SALES_TAX = 0.085;

Dont import a class is it is not used in a source file.


Remove variables that are never used.
All variables should be declared at the beginning of the method for easy access.
A better implementation of an algorithm should use the least resource. For example, a cast such as (int) should be used as
needed. In this project 1, only ONE (int) is allowed.
Debug:
All errors (compile-time errors, run-time errors, and logical errors) must be detected and removed.
Documentation:
Comments are required almost everywhere in a source file. Double check to make sure they are completed in the required
formats.

Project 1 Basics (Chapter 2)

Due: see calendar

Files to be submitted:
Algorithm of method main a normal text file
Java Source code a Java source file
Supporting files if any
Write an application that reads a monetary amount, and then determines the fewest number of each bill and coin needed to
represent that amount, starting with the highest (assuming $10 bill is the maximum size needed).
Sample run: (Your sample runs must follow the exact format.)
Enter monetary amount: 47.63
That's equivalent to:
4 ten dollar bills
1 five dollar bills
2 one dollar bills
2 quarters
1 dimes
0 nickels
3 pennies
Hint:
Declare variables at the beginning of a method. In general, all input values, all output values, and important values of
processing must be stored. The following list shows variables needed for this project.
originalAmount - the original amount, such as 47.63
amountInPennies the amount in pennies, such as 4763
remainBalance - the current balance after each bill or coin, such as 763
tenDollar the number of $10
fiveDollar the number of $5
oneDollar the number of $1
quarter the number of $0.25
dime the number of $0.10
nickel the number of $0.05
penny the number of $0..01
Division in computer programming can be integer division or floating point number division. If one operand or both
operands are integers, the result is an integer. If one operand or both operands are floating point numbers, the result is a
floating point number. A floating point number division (/) returns a result (quotient) including decimal part. An integer
number division (/) returns a result (quotient) with decimal part removed. Use Remainder operation (%) to calculate a
remainder.
Division Operation
Expression
13 / 2
13.0 / 2
13 / 2.0
13.0 / 2.0

Result
6
6.5
6.5
6.5

Remainder Operation
Expression
13 % 2
13.o % 2
13 % 2.0
13.0 % 2.0

Result
1
1.0
1.0
1.0

Integer division is more efficient in this project. First, convert the monetary amount (a double value) to an equivalent
penny amount (an int value), and then use the equivalent penny amount to calculate the fewest number of each bill and
coin. For example, if 47.63 is entered, the equivalent penny amount should be 4763. 47.63 x 100 returns 4763.0 (a double
value). And then remove the decimal part with a proper cast. Of course, each money measurement must be converted as
penny amount. For example, $10 is 1000 pennies; $1 is 100 pennies; and $0.25 is 25 pennies etc.
7

Next, use the equivalent penny amount to calculate the fewest number of $10 bill in a division operation, and then
calculate the remaining balance in a remainder operation. The remaining balance should be used to calculate the next
number.

You might also like