The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 408 Weeks Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
I would like my solutions to my coursework written in Java Language. They need to be written in Java Language & Java Code. Cheers. When you have completed the Assignment Solutions, please clearly identify, label & attach each completed file separately, as you did before. Cheers.
G51OOP unit 2 exercise travel3: Travel times (weight 4%) ======================================================== Introduction ============ To make the program more realistic, the journey undertaken will now involve several different road types. Problem specification ===================== You are to write a program to repeatedly read a single character representing the type of road and a distance in kilometres (as a "double") and compute and print the time in seconds and in hours, minutes and seconds that it would take to travel that distance where the speed depends on the type of road as follows: type m (motorway) 85 kph type a (A road) 70 kph type b (B road) 55 kph type u (urban) 40 kph Other characters are invalid. You need to then prompt the user as to whether there is another leg of the journey. Method ====== Declare the speeds as constants. Read the road type, and use a "switch" statement (NOT "IF" statements on this occasion) to set the actual speed accordingly. If an invalid road type is entered you are to print the error message: Invalid road type X where X is the invalid character and use System.exit( -1 ) in order to force your program to terminate, do not attempt to read the distance. If the type is valid, read the distance as a "double" value, and convert it to seconds of travel using the formula time = distance / speed if the user enters a value for the distance which is less than or equal to zero you are to print the following error message: Illegal Distance Value and start again by prompting for a new road type. You are to print the results for each road type in the previous travel exercisek and as shown below eg. To travel 1234.0 road type m takes 52263 seconds To travel 1234.0 road type m takes 14 hours 31 minutes 3 seconds Once printed you are to prompt the user: Another Road (y/n): If the user enters a 'y' or...G51OOP u2 - Debugging: (Weight: 2)Â
==================================
Â
Introduction
============
Â
This is the first problem you will receive where youÂ
are to debug a program that has already been written.Â
Â
The program may look complicated but is in fact fairly easy
and already written for you, you just need to read it carefully
to spot the glaring errors. Â
Â
NOTE
====
Â
Coursemarker does not like Eclipse's default indentation styleÂ
for switch statements. Coursemarker insists that case statements
are indented within the switch body, whereas Eclipse leaves them
flush in line with the switch.
Â
Either manually indent everything by highlighting it and pressing tab
OR
Edit Eclipse's code formatter settings (google this or ask a preceptor)
Â
Â
Problem specification
=====================
Â
You are to fix a program that imitates everyone's favourite
Harry Potter author JK Rowling. Â The program should first print
a menu stating the following:
Â
G51OOP's JK Rowling Impersonator
Â
a) Count My Money
b) Title of the next book
q) Quit
Â
Make a Choice (a/b/q):
Â
At which point you are to read the character the user has entered.
This character corresponds to the menu option required. Â If the user
enters 'a' (or 'A' - capitals are also allowed) then the program should prompt
the user with:
Â
Enter a number:
Â
At which point you are to read an integer from the user. This number should be
greater than or equal to 1000; if it is not then you are to throw an error (see errorÂ
conditions below). Â If it is greater than or equal to 1000, then the program shouldÂ
then perform the following calculation:
Â
Multiply the number by 27 then divide by 8 and then add 9
Â
You are then to print the statement:
Â
I have XXX pounds
Â
Where XXX is the answer calculated.
Â
If the user enters b or B you are to print the title of the next
book in the series:
Â
Harry Potter goes to the dentist
Â
If the user enters q or Q you are to print:
Â
Time to turn people into Toads
Â
and exit the program.
Â
If the user enters anything else then you are to print:
Â
Illegal value entered into menu
Â
and exit the program with the value -1.
Â
MethodÂ
======
Â
You are to use all debugging methods available to you to try and
find the collection of logical and compilation errors. Â Your lab
demonstrator is able to assist you in the explanation of the debugging
methods but not how to solve the problem itself. Â Â
Â
Notes
=====
Â
Both upper and lower case is allowed for the selection of menu
options.Â
Â
You have three (3) submissions.
Â
Error conditions
================
Â
If when reading in an int from the user they enter a value that isÂ
not greater than or equal to 1000, then you are to print:
Â
I have more money than that!
Â
and not perform the calculation at all. Â Â
Â
If the user enters anything that it not a, A, b, B, q, or Q then
you should print the following:
Â
Illegal value entered into menu
Â
and exit the program with the value -1.
Â
Mark scheme
===========
Â
60% : Dynamic correctness
10% : Typographic quality
30% : Program features
Â
Typical inputÂ
=============
Â
G51OOP's JK Rowling Impersonator
Â
a) Count My Money
b) Title of the next book
q) Quit
Â
Make a Choice (a/b/q): a
Enter a number: 1001
Â
Corresponding outputÂ
====================
Â
I have 3387 pounds
G51OOP u2 exercise Debug2: (Weight: 4%)Â
==================================
Â
Introduction
=========
Â
Again you have another semi complete exercise to debug.
However this time with the introduction of loops, makeÂ
sure that you test your program properly.
Â
If CourseMarker seems to have frozen and you can't access
the screen, it has *NOT* crashed, it is just waiting forÂ
your program to time out due to an infinite loop you've
got yourself stuck in. Â Do NOT quit the program, waitÂ
until control returns a few minutes later otherwise you
may well encounter some unexpected results.
Â
Best still is to test your program FIRST, thoroughly before submitting
it to CourseMarker.
Â
Problem specification
=====================
Â
You are to write a program that helps you perform basic maths
tasks, working out factorials, powers and primes. Â Start by
printing the menu
Â
Welcome to the G51OOP Maths Helper
Â
Pick the problem you want help with.
Â
a) factorial
b) powers
c) prime number
q) Quit
Â
Your choice:Â
Â
and read in their choice as a character.
Â
If the user selects a, you are to prompt the user for a number
Â
Enter the factorial:
Â
this is the factorial you are to work out. Â You obtain theÂ
factorial value by multiplying every number between 1 and X
together, e.g.
Â
factorial of 4 is 1 * 2 * 3 * 4
Â
when you should print the answer in the form
Â
The factorial of X is Y
Â
if the user selects b, you are to prompt the user for 2 numbers,
the value and the power to raise it to
Â
Enter the value:Â
Enter the power:Â
Â
So 2 to the power of three, or 2 cubed is
Â
2 * 2 * 2
Â
and then print the answer in the form
Â
a to the power of b is c
Â
If the user enters c you are to prompt them to enter a number
Â
Enter a number to prime check:
Â
and then test to see if is a prime, prime numbers are those which
are only divisible by 1 and themselves
Â
e.g. 3, 5, 7, 11, 13
Â
you are then to print
Â
x is prime
Â
or
Â
x is not prime
Â
depending on the calculation results.
Â
If the user enters q you are to quit the program.
Â
MethodÂ
======
Â
You are to use all debugging methods available to you to try and
find the collection of logical and compilation errors. Â Your lab
demonstrator is able to assist you in the explanation of the debugging
methods but not how to solve the problem itself. Â Â
Â
Notes
=====
Â
Both upper and lower case is allowed for the selection of menu
options.Â
Â
Please note that the factorial and power values will get very big very
quickly so when you are testing your solution you may find it better
to use small values.
Â
You have three (3) submissions.
Â
Error conditions
================
Â
The users should be allowed both upper and lower case for
the menu choices. Â However any other option that has notÂ
already been mentioned should be counted as an error andÂ
print the messageÂ
Â
Illegal menu option
Â
then return to the main menu and start again.
Â
When creating the powers both the value and the power, in
our example should be positive and greater than zero. Â IfÂ
not print the message
Â
Illegal number value
Â
or
Â
Illegal power value
Â
If users enters an Illegal number value, then you should not prompt for the power value.
Â
You can assume all other values will be correct. Â
Â
Mark scheme
===========
Â
70% : Dynamic correctness
10% : Typographic quality
20% : Program features
Â
Typical input / outputÂ
======================
Â
Welcome to the G51OOP Maths Helper
Â
Pick the problem you want help with.
Â
a) factorial
b) powers
c) prime number
q) Quit
Â
Your choice: a
Â
Enter the factorial: 4
Â
The factorial of 4 is 24
Â
Welcome to the G51OOP Maths Helper
Â
Pick the problem you want help with.
Â
a) factorial
b) powers
c) prime number
q) Quit
Â
Your choice: q
Â
Quitting
G51OOP u2 exercise Debug2: (Weight: 4%)Â
==================================
Â
Introduction
=========
Â
Again you have another semi complete exercise to debug.
However this time with the introduction of loops, makeÂ
sure that you test your program properly.
Â
If CourseMarker seems to have frozen and you can't access
the screen, it has *NOT* crashed, it is just waiting forÂ
your program to time out due to an infinite loop you've
got yourself stuck in. Â Do NOT quit the program, waitÂ
until control returns a few minutes later otherwise you
may well encounter some unexpected results.
Â
Best still is to test your program FIRST, thoroughly before submitting
it to CourseMarker.
Â
Problem specification
=====================
Â
You are to write a program that helps you perform basic maths
tasks, working out factorials, powers and primes. Â Start by
printing the menu
Â
Welcome to the G51OOP Maths Helper
Â
Pick the problem you want help with.
Â
a) factorial
b) powers
c) prime number
q) Quit
Â
Your choice:Â
Â
and read in their choice as a character.
Â
If the user selects a, you are to prompt the user for a number
Â
Enter the factorial:
Â
this is the factorial you are to work out. Â You obtain theÂ
factorial value by multiplying every number between 1 and X
together, e.g.
Â
factorial of 4 is 1 * 2 * 3 * 4
Â
when you should print the answer in the form
Â
The factorial of X is Y
Â
if the user selects b, you are to prompt the user for 2 numbers,
the value and the power to raise it to
Â
Enter the value:Â
Enter the power:Â
Â
So 2 to the power of three, or 2 cubed is
Â
2 * 2 * 2
Â
and then print the answer in the form
Â
a to the power of b is c
Â
If the user enters c you are to prompt them to enter a number
Â
Enter a number to prime check:
Â
and then test to see if is a prime, prime numbers are those which
are only divisible by 1 and themselves
Â
e.g. 3, 5, 7, 11, 13
Â
you are then to print
Â
x is prime
Â
or
Â
x is not prime
Â
depending on the calculation results.
Â
If the user enters q you are to quit the program.
Â
MethodÂ
======
Â
You are to use all debugging methods available to you to try and
find the collection of logical and compilation errors. Â Your lab
demonstrator is able to assist you in the explanation of the debugging
methods but not how to solve the problem itself. Â Â
Â
Notes
=====
Â
Both upper and lower case is allowed for the selection of menu
options.Â
Â
Please note that the factorial and power values will get very big very
quickly so when you are testing your solution you may find it better
to use small values.
Â
You have three (3) submissions.
Â
Error conditions
================
Â
The users should be allowed both upper and lower case for
the menu choices. Â However any other option that has notÂ
already been mentioned should be counted as an error andÂ
print the messageÂ
Â
Illegal menu option
Â
then return to the main menu and start again.
Â
When creating the powers both the value and the power, in
our example should be positive and greater than zero. Â IfÂ
not print the message
Â
Illegal number value
Â
or
Â
Illegal power value
Â
If users enters an Illegal number value, then you should not prompt for the power value.
Â
You can assume all other values will be correct. Â
Â
Mark scheme
===========
Â
70% : Dynamic correctness
10% : Typographic quality
20% : Program features
Â
Typical input / outputÂ
======================
Â
Welcome to the G51OOP Maths Helper
Â
Pick the problem you want help with.
Â
a) factorial
b) powers
c) prime number
q) Quit
Â
Your choice: a
Â
Enter the factorial: 4
Â
The factorial of 4 is 24
Â
Welcome to the G51OOP Maths Helper
Â
Pick the problem you want help with.
Â
a) factorial
b) powers
c) prime number
q) Quit
Â
Your choice: q
Â
Quitting
G51OOP unit 2 exercise travel3: Travel times (weight 4%)
========================================================
Â
Introduction
============
Â
To make the program more realistic, the journey undertaken will now involve
several different road types.
Â
Problem specification
=====================
Â
You are to write a program to repeatedly read
Â
a single character representing the type of road and
a distance in kilometres (as a "double")
Â
and compute and print the time in seconds and in hours, minutes and seconds that
it would take to travel that distance where the speed depends on the type of road
as follows:
Â
type m (motorway) 85 kph
type a (A road) Â Â Â Â 70 kph
type b (B road) Â Â Â Â 55 kph
type u (urban) Â Â Â Â Â 40 kph
Â
Other characters are invalid. Â You need to then prompt the user as to whether thereÂ
is another leg of the journey. Â
Â
MethodÂ
======
Â
Declare the speeds as constants.Â
Â
Read the road type, and use a "switch" statement (NOT "IF" statements on this occasion)
to set the actual speed accordingly. If an invalid road type is entered
you are to print the error message:
Â
Invalid road type X
Â
where X is the invalid character and use System.exit( -1 ) in orderÂ
to force your program to terminate, do not attempt to read the distance.
Â
If the type is valid, read the distance as a "double" value, and convert it to seconds of travelÂ
using the formula
Â
time = distance / speed
Â
if the user enters a value for the distance which is less than or equal
to zero you are to print the following error message:
Â
Illegal Distance Value
Â
and start again by prompting for a new road type. Â
Â
You are to print the results for each road type in the previous travel exercisek and as shownÂ
below eg.Â
Â
To travel 1234.0 road type m takes 52263 seconds
To travel 1234.0 road type m takes 14 hours 31 minutes 3 seconds
Â
Once printed you are to prompt the user:
Â
Another Road (y/n):
Â
If the user enters a 'y' or 'Y' you are to ask the user to enter details
for the next stage of their journey. Â
Â
When the user's journey has been completely entered you are to print
the total distance travelled and total time taken in seconds
Â
To complete your journey of xxx km takes yyy seconds
Â
and then quit. Â
Â
HintsÂ
=====
Â
Be careful of units! If distance is in kilometres and speed is in kilometresÂ
per hour, the above formula gives the result in hours!
Â
There should only be ONE "if" statement in your program!
Â
Choose your loop type carefully.
Â
Notes
=====
Â
You have three (3) submissions.
Â
Error conditions
================
Â
If the road type is not one of the given 4 characters (but do allow capitals i.e. 4 * 2), print the message
Â
Invalid road type x
Â
where "x" is the invalid character and
also use System.exit( -1 ) in order to force your program to terminate before
it reads a distance value.
Â
If the distance is not greater than zero you are to print the message
Â
Illegal Distance Value
Â
and ask the user for a new road type. Â
Â
Mark scheme
===========
Â
80% : Dynamic correctness
10% : Typographic tests
10% : Feature tests
Â
Typical input/outputÂ
====================
Â
Type the road type: Â m
Type the travel distance: Â 1234
Â
To travel 1234.0 takes 52263 seconds
To travel 1234.0 road type m takes 14 hours 31 minutes 3 seconds
Â
Another Road (y/n): Â y
Â
Type the road type: Â a
Type the travel distance: Â 15
Â
To travel 15.0 takes 771 seconds
To travel 15.0 road type a takes 0 hours 12 minutes 51 seconds
Â
Another Road (y/n): Â n
Â
To complete your journey of 1249.0 km takes 53034 seconds
Â
G51OOP unit 2 exercise travel3: Travel times (weight 4%)
========================================================
Â
Introduction
============
Â
To make the program more realistic, the journey undertaken will now involve
several different road types.
Â
Problem specification
=====================
Â
You are to write a program to repeatedly read
Â
a single character representing the type of road and
a distance in kilometres (as a "double")
Â
and compute and print the time in seconds and in hours, minutes and seconds that
it would take to travel that distance where the speed depends on the type of road
as follows:
Â
type m (motorway) 85 kph
type a (A road) Â Â Â Â 70 kph
type b (B road) Â Â Â Â 55 kph
type u (urban) Â Â Â Â Â 40 kph
Â
Other characters are invalid. Â You need to then prompt the user as to whether thereÂ
is another leg of the journey. Â
Â
MethodÂ
======
Â
Declare the speeds as constants.Â
Â
Read the road type, and use a "switch" statement (NOT "IF" statements on this occasion)
to set the actual speed accordingly. If an invalid road type is entered
you are to print the error message:
Â
Invalid road type X
Â
where X is the invalid character and use System.exit( -1 ) in orderÂ
to force your program to terminate, do not attempt to read the distance.
Â
If the type is valid, read the distance as a "double" value, and convert it to seconds of travelÂ
using the formula
Â
time = distance / speed
Â
if the user enters a value for the distance which is less than or equal
to zero you are to print the following error message:
Â
Illegal Distance Value
Â
and start again by prompting for a new road type. Â
Â
You are to print the results for each road type in the previous travel exercisek and as shownÂ
below eg.Â
Â
To travel 1234.0 road type m takes 52263 seconds
To travel 1234.0 road type m takes 14 hours 31 minutes 3 seconds
Â
Once printed you are to prompt the user:
Â
Another Road (y/n):
Â
If the user enters a 'y' or 'Y' you are to ask the user to enter details
for the next stage of their journey. Â
Â
When the user's journey has been completely entered you are to print
the total distance travelled and total time taken in seconds
Â
To complete your journey of xxx km takes yyy seconds
Â
and then quit. Â
Â
HintsÂ
=====
Â
Be careful of units! If distance is in kilometres and speed is in kilometresÂ
per hour, the above formula gives the result in hours!
Â
There should only be ONE "if" statement in your program!
Â
Choose your loop type carefully.
Â
Notes
=====
Â
You have three (3) submissions.
Â
Error conditions
================
Â
If the road type is not one of the given 4 characters (but do allow capitals i.e. 4 * 2), print the message
Â
Invalid road type x
Â
where "x" is the invalid character and
also use System.exit( -1 ) in order to force your program to terminate before
it reads a distance value.
Â
If the distance is not greater than zero you are to print the message
Â
Illegal Distance Value
Â
and ask the user for a new road type. Â
Â
Mark scheme
===========
Â
80% : Dynamic correctness
10% : Typographic tests
10% : Feature tests
Â
Typical input/outputÂ
====================
Â
Type the road type: Â m
Type the travel distance: Â 1234
Â
To travel 1234.0 takes 52263 seconds
To travel 1234.0 road type m takes 14 hours 31 minutes 3 seconds
Â
Another Road (y/n): Â y
Â
Type the road type: Â a
Type the travel distance: Â 15
Â
To travel 15.0 takes 771 seconds
To travel 15.0 road type a takes 0 hours 12 minutes 51 seconds
Â
Another Road (y/n): Â n
Â
To complete your journey of 1249.0 km takes 53034 seconds
Â
Â
Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â----------- -----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------. P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll