0% found this document useful (0 votes)
87 views3 pages

COMP1405 - Assignment #2: (1) Cell Phone Usage

This document outlines 4 programming assignments for a COMP1405 course. The assignments involve: 1) A program to calculate cell phone coverage between 4 cities based on user-inputted ranges 2) A program to convert English sentences to Morse code 3) A program for a simulated spending spree where the user purchases items until funds are depleted 4) A program to convert Morse code sequences back to English sentences Students are instructed to submit a zip folder called "Ass2" containing all Java files by the due date and time. Proper formatting and inclusion of all files is required to receive full marks.

Uploaded by

Anna Gow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views3 pages

COMP1405 - Assignment #2: (1) Cell Phone Usage

This document outlines 4 programming assignments for a COMP1405 course. The assignments involve: 1) A program to calculate cell phone coverage between 4 cities based on user-inputted ranges 2) A program to convert English sentences to Morse code 3) A program for a simulated spending spree where the user purchases items until funds are depleted 4) A program to convert Morse code sequences back to English sentences Students are instructed to submit a zip folder called "Ass2" containing all Java files by the due date and time. Proper formatting and inclusion of all files is required to receive full marks.

Uploaded by

Anna Gow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

COMP1405 - Assignment #2

(Due: Monday, October 5th at 9:00AM)


(1) Cell Phone Usage
You want to plan a trip through 4 cities and
bring your cell phone along, which you plan
to use while driving. Write a program
called CellPhoneProgram that has the
(x,y) coordinates of these 4 cities hard
coded using static final constants.
The program should ask the user for the
maximum distance (i.e., range shown here)
that you may be from each city center (in
kms) before your cell phone service does
not work(using either the Scanner class or
the showInputDialog()) . You must
create a static function called getRange()
that takes a city number as a parameter
and the function should ask the user to
enter the range for that city (e.g., "Enter
maximum cell phone connectivity
distance for city 1: ") and then

return
the range as an integer obtained from the
user.
The main program should call this function
4 times to get the information from the user and then it should then display a message indicating whether
or not you can travel from city 1 to city 2 to city 3 and finally to city 4 without losing cell phone service
along the way.
You may say something like "Cell phone service will become unavailable" or "Cell phone service
will remain available". In order to determine whether or not cell service is lost along the way, you will
need to make sure that the circle around city1 overlaps with the circle around city2, and that city2's circle
overlaps with city 3's circle, etc... So, the distance between two adjacent city centers must be less than
the sum of the two city ranges in order for the cell phone service not to be lost You must also create a
static function called distance() that will calculate the distance between two cities as follows:
distance = the square root of ((Xb - Xa)2 + (Yb - Ya)2) where the cities have coordinates
(Xa,Ya) and (Xb,Yb), respectively.
Make sure to test your code with the different city cell phone ranges shown in the following table:
Range 1
85
85
80
65

Range 2
75
75
80
75

Range 3
115
50
80
75

Range 4
65
65
80
125

Answer
remains available
becomes unavailable
remains available
becomes unavailable

(2) Morse Code


Write a program called MorseCodeProgram that asks
the user for an English sentence containing only
uppercase characters and spaces (i.e., no numbers,
punctuation or special symbols). The program should
then display the sentence in Morse Code. To do this,
you should use charAt(i) to get the ith character from
the entered sentence and then use a switch statement
to determine the Morse Code (see chart here) to
display for that letter. You should leave a space
between each character and you should leave 3
spaces between each word. Here is a sample run of the program:
Enter the sentence to be converted to Morse Code (letters and spaces only, no numbers or punctuation):
I LOVE JAVA
Here is your sentence in Morse Code:
..
.-.. --- ...- .
.--- .- ...- .-

(3) Spending Spree


Write a program called SpendingSpreeProgram that allows the user to keep track of items being
purchased on a quick purchasing spending spree. The program should allows the user to start with
$1000 and then ask him/her repeatedly to enter costs of items to be purchased, confirming every
purchase. The program should allow purchases to be made until there is no more money left. The
program should end when the user has no money left or has gone into debt from a single over purchase,
at which point the program should confirm beforehand whether that purchase is to be made or not. Here
is an example of the output that you should see from your program:
You have $1000.00 money remaining to spend.
Enter the cost of the item that you want to buy
9.99
Are you sure that you want to purchase the $9.99 item ?
yes
You have $990.01 money remaining to spend.
Enter the cost of the item that you want to buy
543.23
Are you sure that you want to purchase the $543.23 item
no
You have $990.01 money remaining to spend.
Enter the cost of the item that you want to buy
232.65
Are you sure that you want to purchase the $232.65 item
yes
You have $757.36 money remaining to spend.
Enter the cost of the item that you want to buy
700
Are you sure that you want to purchase the $700.00 item
yes
You have $57.36 money remaining to spend.
Enter the cost of the item that you want to buy
789.23
You don't have enough money to purchase that item.
Are you sure that you want to purchase the $789.23 item
yes
You have spent too much money and now owe: $731.87

(yes or no)

? (yes or no)

? (yes or no)

? (yes or no)

and go into debt ? (yes or no)

(4) Reverse Morse Code


Write a program called ReverseMorseCodeProgram that asks the user for a Morse Code sequence
and then converts the sequence into an English sentence (assuming it contains only letters and spaces)
and displays it. Notice that each letter contains at most 4 "dot/dash" characters. Your program MUST
first determine the dots and dashes that make up a single letter sequence and then decode/display that
letter before moving on to the next letter. To do this, you MUST go through the code sequence and
create a string of dots and dashes that make up a single letter of the sentence (i.e., append to a blank
string until a space is found (include the space in the letter's sequence as well)). You MUST then call a
function called decodeLetter(String s) which then takes that letter's sequence and displays the
appropriate uppercase letter that it corresponds to.
Here are some secret code sequences to try out:
- .... .. ...
.. ...
.... . -.-. .-. . -- . ... ... .- --. .
-- -.-..-. .- ...- --- ..- .-. .. - .
-.-. --- .-.. --- .-.
.. ...
.-. . -..
.--. .. --.. --.. ... ...
.- -- .- --.. .. -. --.
..-. --- --- -..
-.. ---. --- . .- -.-- . .-.. .-.. --- .-... -. --- .--.. ---. --- ..-. .- .. .-..
- .... .. ...
.- ... ... .. --. -. -- . -. -

NOTE: Submit a zipped file (not RAR) of a folder called Ass2 which contains all of your .java files (i.e., not .class files).
Submit your assignment using CULearn. Note that if your internet connection at home is down or does not work, we will not
accept this as a reason for handing in an assignment late ... so make sure to submit the assignment WELL BEFORE it is due !

Please NOTE that you WILL lose marks on this assignment if any of your files are missing. You
may also lose marks if your code is not written neatly with proper indentation. See examples in
the notes for proper style.

You might also like