CompSci 101 S2 C 2010 – A SSIGNMENT O NE –
Conversion Program
ASSESSMENT
• Programming due: 5:30pm, Monday 23rd August, 2010
• Worth: 4% of your final mark
AIMS OF THE ASSIGNMENT
Implement a program using Java for various number and string manipulations, and practise using
• variables,
• expressions,
• methods,
• strings, and
• conditional statements
ASSIGNMENT DETAILS
Your program will allow the user to perform 6 kinds of conversions:
1. Convert a length from Miles to Kilometres and vice versa
2. Convert a temperature from Celsius to Fahrenheit and vice versa 3. Convert a full name into initials
4. Convert a date from a New Zealand format to a Standard format 5. Convert seconds into an “hours:minutes:seconds” format
6. Convert an English word into a Pig Latin form
(http://en.wikipedia.org/wiki/Pig_Latin, however simplified for this assignment)
Three Java files are provided, they are:
1. ConversionApplication.java - the Java Application to run 2. Keyboard.java - the program to read input from the Keyboard 3. ConversionProgram.java – the implementation of the program
You must NOT change the first two files. You will need to understand the provided skeleton of the ConversionProgram class before adding further implementation.
The program SKELETON
public class ConversionProgram { public void start() {
String userChoice = askConversionCategory();
while (userChoice.equals("1") || userChoice.equals("2") ||
userChoice.equals("3") || userChoice.equals("4") ||
userChoice.equals("5") || userChoice.equals("6")) { processConversionRequest(userChoice);
userChoice = askConversionCategory();
}
System.out.println("Good Bye!");
}
private String askConversionCategory() { System.out.println();
String prompt = "Select a conversion category, enter \n" +
"\t\"1\" to convert Length, \n" +
"\t\"2\" to convert Temperature, \n" +
"\t\"3\" to convert Initials, \n" + "\t\"4\" to convert Date, \n" + "\t\"5\" to convert Time, \n" +
"\t\"6\" to convert Pig Latin, and\n" + "\tany other key to quit: ";
String category = acquireInput(prompt);
return category;
}
private void processConversionRequest(String userChoice) { if (userChoice.equals("1")) {
convertLength();
} else if (userChoice.equals("2")) { convertTemperature();
} else if (userChoice.equals("3")) { convertInitials();
} else if (userChoice.equals("4")) { convertDate();
} else if (userChoice.equals("5")) { convertTime();
} else if (userChoice.equals("6")) { convertPigLatin();
} }
private void convertLength(){
}
private void convertTemperature(){
}
private void convertInitials(){
}
private void convertDate(){
}
private void convertTime(){
}
private void convertPigLatin(){
}
private String acquireInput(String prompt){
System.out.print(prompt);
String input = Keyboard.readInput().trim();
return input;
} }
NOTE:
for this assignment you are required to add a section of code to the start() method and to complete the 6 helper methods which make this program execute as described. You must add your own methods to structure your program.Stage 1 - 4 marks
Add code to the start() method so that the first line of output is the String "A
Conversion Program by " with YOUR UPI added to the end of the String. In the following example output I have displayed the String with the UPI "upi001".
A Conversion Program by upi001
Marking Schedule for Stage 1 Stage 1
The first line of the program output displays "A Conversion Program by" (2) The student's UPI is displayed in the first line of the program output (2)
Stage 2 convertLength() method - 15 marks
The convertLength() method is used to ask the user to choose a sub conversion category (Miles to Kilometres, or Kilometres to Miles), acquire a double
Miles/Kilometres input, convert the value to its counterpart and display the conversion result. The output of the program so far should be, for example:
A Conversion Program by upi001
Select a conversion category, enter "1" to convert Length,
"2" to convert Temperature, "3" to convert Initials,
"4" to convert Date,
"5" to convert Time,
"6" to convert Pig Latin, and any other key to quit: 1
Select a conversion, enter
"1" to convert Miles to Kilometres,
"2" to convert Kilometres to Miles: 1 Enter Miles: 100
Conversion result: 100.0 Miles = 160.93444978925635 Kilometres
The following formulas should be used for implementing the conversions:
• miles = 0.621371 * kilometres
• kilometres = miles / 0.621371
Marking Schedule for Stage 2 Stage 2 – convertLength()
The program acquires a user input for a choice of conversion (2) The program acquires a user input for Miles or Kilometres (2) The program computes the conversion from Miles to Kilometres correctly (5) The program computes the conversion from Kilometres to Miles correctly (5) The program displays the conversion result as in the example output (1)
Stage 3 convertTemperature() method - 15 marks
The convertTemperature() method is used to ask the user to choose a sub conversion (Celsius to Fahrenheit, or Fahrenheit to Celsius), acquire an integer
Celsius/Fahrenheit input, convert the value to its counterpart (integer output) and display the conversion result. The output of the program should be, for example:
A Conversion Program by upi001
Select a conversion category, enter "1" to convert Length,
"2" to convert Temperature, "3" to convert Initials,
"4" to convert Date,
"5" to convert Time,
"6" to convert Pig Latin, and any other key to quit: 2
Select a conversion, enter
"1" to convert Celsius to Fahrenheit,
"2" to convert Fahrenheit to Celsius: 2 Enter Fahrenheit: 90
Conversion result: 90 degrees Fahrenheit = 32 degrees Celsius
The following formulas should be used for implementing the conversions:
• fahrenheit = 32 + 9/5.0 * celsius
• celsius = (fahrenheit – 32) * 5.0/9
Marking Schedule for Stage 3
Stage 3 – convertTemperature()
The program acquires a user input for a choice of conversion (2) The program acquires a user input for Celsius or Fahrenheit (2) The program computes the conversion from Celsius to Fahrenheit correctly (5) The program computes the conversion from Fahrenheit to Celsius correctly (5) The program displays the conversion result as in the example output (1)
Stage 4 convertInitials() method - 8 marks
The convertInitials() method is used to acquire a full name input (a first name followed by a space and then followed by a surname), convert it to initials and display the conversion result. The output of the program should be, for example:
A Conversion Program by upi001
Select a conversion category, enter "1" to convert Length,
"2" to convert Temperature, "3" to convert Initials,
"4" to convert Date,
"5" to convert Time,
"6" to convert Pig Latin, and any other key to quit: 3
Enter your full name separated by a space: Karen Li Conversion result: Karen Li = KL
Marking Schedule for Stage 4 Stage 3 – convertInitials()
The program acquires a full name input (2)
The program converts a full name into initials correctly (5) The program displays the conversion result as in the example output (1)
Stage 5 convertDate() method - 8 marks
The convertDate() method is used to acquire a date input in a New Zealand format (01/08/2010), convert it to a Standard format (2010-08-01) and display the conversion result. The output of the program should be, for example:
A Conversion Program by upi001
Select a conversion category, enter "1" to convert Length,
"2" to convert Temperature, "3" to convert Initials,
"4" to convert Date,
"5" to convert Time,
"6" to convert Pig Latin, and any other key to quit: 4
Enter date in New Zealand format: 01/08/2010
Conversion result: 01/08/2010 = 2010-08-01 Standard format
Marking Schedule for Stage 5
Stage 3 – convertDate()
The program acquires a date input (2)
The program converts a New Zealand date into a Standard date correctly (5) The program displays the conversion result as in the example output (1)
Stage 6 convertTime() method - 18 marks
The convertTime() method is used to acquire an input of seconds, convert it to an
“hours:minutes:seconds” format and display the conversion result. The output of the program should be, for example:
A Conversion Program by upi001
Select a conversion category, enter "1" to convert Length,
"2" to convert Temperature, "3" to convert Initials,
"4" to convert Date,
"5" to convert Time,
"6" to convert Pig Latin, and any other key to quit: 5
Enter seconds: 2000
Conversion result: 2000 seconds = 0:33:20
Marking Schedule for Stage 6 Stage 3 – convertTime()
The program acquires an input of seconds (2)
The program converts seconds into the “hours” part correctly (5) The program converts seconds into the “minutes” part correctly (5) The program converts seconds into the “seconds” part correctly (5) The program displays the conversion result as in the example output (1)
Stage 7 convertPigLatin() method - 12 marks
The convertPigLatin() method is used to acquire an English word input, convert it to a Pig Latin format and display the conversion result. The output of the program should be, for example:
A Conversion Program by upi001
Select a conversion category, enter "1" to convert Length,
"2" to convert Temperature, "3" to convert Initials,
"4" to convert Date,
"5" to convert Time,
"6" to convert Pig Latin, and any other key to quit: 6
Enter a word: happy
Conversion result: happy = appy-hay
The following rules should be used for implementing the conversion:
• In words that begin with consonant sounds, the initial consonant is moved to the end of the word (after a hyphen), and “ay” is added
• In words that begin with vowel sounds, “way” is added to the end of the word (after a hyphen)
Marking Schedule for Stage 7 Stage 3 – convertPigLatin()
The program acquires an English word input (2)
The program converts words that begin with vowels into Pig Latin correctly (4) The program converts words that begin with consonants into Pig Latin correctly (5) The program displays the conversion result as in the example output (1)
Sample conversion results to test against
The following table shows some conversion results produced by the program:
Conversion Result Miles to
Kilometres
1.0 Miles = 1.6093444978925633 Kilometres 6.5 Miles = 10.460739236301661 Kilometres Kilometres to
Miles
1.0 Kilometres = 0.621371 Miles 30.0 Kilometres = 18.64113 Miles Celsius to
Fahrenheit
38 degrees Celsius = 100 degrees Fahrenheit 100 degrees Celsius = 212 degrees Fahrenheit Fahrenheit to
Celsius
18 degrees Fahrenheit = -7 degrees Celsius 100 degrees Fahrenheit = 37 degrees Celsius Note that the program will generate backward-incompatible results (e.g. 38 degrees Celsius = 100 degrees
Fahrenheit, but 100 degrees Fahrenheit = 37 degrees Celsius) due to the truncation of decimal digits. This is acceptable.
Full name to Initials
Harry Potter = HP New Zealand = NZ NZ date to
Standard date
24/2/2000 = 2000-2-24 Standard format 06/03/2009 = 2009-03-06 Standard format Seconds to
h:m:s
10 seconds = 0:0:10 10000 seconds = 2:46:40 Word to Pig
Latin
eat = eat-way
treasure = reasure-tay
GETTING HELP:
The lecturer who issued this assignment (Karen) will run the following help sessions in FCL (303S-191):
• 11am-1pm Tuesday 17th August
• 1-3pm Friday 20th August
Just turn up in the above sessions if you have a question or need guidance.
You can also visit any of the other teaching staff (Adriana, Jing or Ann).
There are also undergraduate lab demonstrators in FCL (303S-191) and OCL (303S-130) who are able to help you with the assignment.
SUMMARY OF SUBMISSION INSTRUCTIONS:
• You should submit the following files for this assignment through the web dropbox (https://adb.ec.auckland.ac.nz/adb/).
o ConversionApplication.java - the Java Application o Keyboard.java - the program to read input from the Keyboard o ConversionProgram.java – the implementation of the program o A1.txt – a text file containing your feedback on the assignment (see
below).
• You can make more than one submission – every submission that you make replaces your previous submission. Only your very latest submission will be marked.
DO NOT SUBMIT SOMEONE ELSE'S WORK:
• If you submit an assignment you are claiming that you did the work. Do not submit work done by others.
• Do not under any circumstances copy anyone else’s work – this will be penalised heavily.
• Do not under any circumstances give a copy of your work to someone else.
• The Computer Science department uses copy detection tools on the files you submit. If you copy from someone else, or allow someone else to copy from you, this copying will be detected and disciplinary action will be taken.
What you should include in the A1.txt file
You must include a text file named A1.txt in your submission. There will be a 5 mark penalty for not doing so.
This text file must contain the following information:
Your name
Your login name and ID number
How much time did the assignment take overall?
What areas of the assignment did you find easy?
What areas of the assignment did you find difficult?
Which topics of the course did the assignment most help you understand?
Any other comments you would like to make.
Marking Schedule Style
Comment at the top of each class with your
name and UPI. (2)
Good identifier names. (3)
Correct indentation. (2)
Uses the methods as described in this
document. (3)
Good use of methods to structure your
program. (10) /20
Stage 1 – Displaying the name of the program and UPI Stage 2 – convertLength() method
Stage 3 – convertTemperature () method Stage 4 – convertInitials() method
Stage 5 – convertDate() method Stage 6 – convertTime() method Stage 7 – convertPigLatin() method
/4
/15 /15 /8 /8 /18 /12
Penalty - A1.txt was not submitted /-5
Grand Total
/100TYPICAL A1.txt FILE
CompSci 101 S2 2010
===================
Feedback on Assignment One ---
Name:
Login:
ID:
All the work done in this assignment is my own work.
How much time did the assignment take overall?
What areas of the assignment did you find easy?
What areas of the assignment did you find difficult?
Which topics of the course did the assignment most help you understand?
Any other comments
TYPICAL MARK FILE
Marking Sheet for: upi001 Marked by: upi002
2010 - Computer Science - CompSci 101 S2 C
Your Marks for COMPSCI 101 S2 C Assignment ONE
Conversion Program STYLE - BY INSPECTION Look at the ConversionProgram class (2/2) : Comment at the top of the class.
(3/3) : Good identifier names.
(2/2) : Correct indentation.
(3/3) : Uses the methods as described in this document.
(10/10) : Good use of methods to structure your program.
--- 20/20
Stage 1 Displaying the name of the game on screen (4 marks) ---
(2/2) : When the program first starts, the name of the program is displayed.
(2/2) : When the program first starts, the student UPI is displayed.
--- 4/4
Stage 2 convertLength() method (15 marks) ---
(2/2) : The program acquires a user input for a choice of conversion.
(2/2) : The program acquires a user input for Miles or Kilometres.
(5/5) : The program computes the conversion from Miles to Kilometres correctly.
(5/5) : The program computes the conversion from Kilometres to Miles correctly.
(1/1) : The program displays the conversion result as in the example output.
--- 15/15
Stage 3 convertTemperature() method (15 marks) ---
(2/2) : The program acquires a user input for a choice of conversion.
(2/2) : The program acquires a user input for Celsius or Fahrenheit.
(5/5) : The program computes the conversion from Celsius to Fahrenheit correctly.
(5/5) : The program computes the conversion from Fahrenheit to Celsius correctly.
(1/1) : The program displays the conversion result as in the example output.
--- 15/15
Stage 4 convertInitials() method (8 marks)
---
(2/2) : The program acquires a full name input.
(5/5) : The program converts a full name into initials correctly.
(1/1) : The program displays the conversion result as in the example output ---
8/8
Stage 5 convertDate() method (8 marks) ---
(2/2) : The program acquires a date input.
(5/5) : The program converts a New Zealand date into a Standard date correctly.
(1/1) : The program displays the conversion result as in the example output.
--- 8/8
Stage 6 convertTime() method (18 marks) ---
(2/2) : The program acquires an input of seconds.
(5/5) : The program converts seconds into the “hours” part correctly.
(5/5) : The program converts seconds into the “minutes” part correctly.
(5/5) : The program converts seconds into the “seconds” part correctly.
(1/1) : The program displays the conversion result as in the example output.
--- 18/18
Stage 7 convertPigLatin() method (12 marks) ---
(2/2) : The program acquires an English word input.
(4/4) : The program converts words that begin with vowels into Pig Latin correctly.
(5/5) : The program converts words that begin with consonants into Pig Latin correctly.
(1/1) : The program displays the conversion result as in the example output.
--- 12/12
Penalty
(0/-5) : A1.txt was not submitted
=============================================
=============================================
Final mark for assignment: not marked/100
=============================================
=============================================
This mark is out of 100. It is worth 4% towards your final grade.
Comments: