Programming Question

College of Computing and InformaticsAssignment 2
Deadline: Tuesday 1/11/2021 @ 23:59
[Total Mark for this Assignment is 8]
Student Details:
Name: ###
ID: ###
CRN: ###
Instructions:
• You must submit two separate copies (one Word file and one PDF file) using the Assignment Template on
Blackboard via the allocated folder. These files must not be in compressed format.
• It is your responsibility to check and make sure that you have uploaded both the correct files.
• Zero mark will be given if you try to bypass the SafeAssign (e.g. misspell words, remove spaces between
words, hide characters, use different character sets, convert text into image or languages other than English
or any kind of manipulation).
• Email submission will not be accepted.
• You are advised to make your work clear and well-presented. This includes filling your information on the cover
page.
• You must use this template, failing which will result in zero mark.
• You MUST show all your work, and text must not be converted into an image, unless specified otherwise by
the question.
• Late submission will result in ZERO mark.
• The work should be your own, copying from students or other resources will result in ZERO mark.
• Use Times New Roman font for all your answers.
Question One
Pg. 01
Learning
Outcome(s):
Develop a
program based on
specification
using
programming
language
elements
including syntax,
data types,
conditional
statement, control
structures,
procedures,
arrays, objects
and classes.
Question One
3 Marks
Write a complete Java program that performs the following tasks:
1. Ask the user to enter his/her full name and print a welcome message using the
user’s name.
2. Ask the user to enter any city.
3. Ask the user to enter the weather temperature.
4. Ask the user to enter 1 or 2 to choose the type of conversion.
5. Write two methods that should take a city and a temperature as arguments, and
print the Celsius or Fahrenheit equivalent, using the following calculations:
Celsius = 5.0 ÷ 9.0 × (Fahrenheit – 32)
Fahrenheit = 9.0 ÷ 5.0 × Celsius + 32
Each method will be called based on the user choice. For example,

if the user enters 1, the method that calculates and prints Celsius is invoked
if the user enters 2, the method that calculates and prints Fahrenheit is
invoked.
Note:


The class name of your Java program must be your first name.
Your answer should have the code as text as well as the screenshot of the
program output (using your own name) as a part of your answer. Otherwise,
zero marks will be awarded.
Typical runs of the program
Question Two
Pg. 02
Learning
Outcome(s):
Develop a
program based on
specification
using
programming
language
elements
including syntax,
data types,
conditional
statement, control
structures,
procedures,
arrays, objects
and classes.
Question Two
2 Marks
Write a complete Java program that performs the following tasks:
1. Create and initialize an array named studID with 9 elements. The array must be
initialized with your student id. For example, if your student ID is 123456749,
you need to take each single digit as the elements of your array.
2. Print the elements of the array using enhanced for loop.
3. Asks the user to give a number between 1 and 9 and save it in a variable num.
4. In the array studID, find and print the following:

Count the numbers divisible by num
Number of even numbers that is less than num
Number of odd numbers that is less than num
The sum of all numbers that are divisible by 3 or by 4.
Note:

The class name of your Java program must be your first name.

Your answer should have the code as text as well as the screenshot of the
program output (using your own student ID) as a part of your answer.
Otherwise, zero marks will be awarded.
Typical run of the program
Question Three
Pg. 03
Learning
Outcome(s):
Explain the basic
principles of
programming,
concept of
language, and
universal
constructs of
programming
languages.
Question Three
3 Marks
Write a complete Java program as follow:
1. Create two java classes:
a. The first class represents a student and must be named using your first
and last name.
b. The second class must be named as “Main” with the main method.
2. Perform the following in the first class:
a.
Create three private instance variables to store first name, last name and
GPA. Do not assign any values to the variables in this step!
b. Create a constructer without parameters to initialize all the instance
variables to default values (0 for numbers and “” for a string).
c. Create a constructor that can take the first and last name as parameters.
Assign the parameters’ values to the two instance variables you created
earlier (first and last name).
d. Create a getName() method to return the first and last name. You must
return the first and last name in a single string using a plus sign. You
must have a space between the first name and last name.
e. Create setGPA() and getGPA() methods to store and return your GPA,
respectively.
3. Perform the following in the main class:
a. Create a new object of your first class and pass your first and last name
as two parameters.
b. Call the getName() method and store the result in a string variable
called myFullName.
c. Print your full name using the string variable myFullName.
d. Set your GPA using the setGPA() method.
e. Print your GPA using the getGPA() method.
Question Three
Pg. 04
Note:

Your answer should have the code as text as well as the screenshot of the
program output (using your own name) as a part of your answer. Otherwise,
zero marks will be awarded.
Typical run of the program

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER