Docsity

Labs and exercises for java, Exercises of Computer Science

Toggle sidebar
bg1
COSC1046K LAB K 24W
COSC1046 Lab 3 - Loops and Methods
Note: you can only use concepts covered up to and including Module 3, Unit 3 of the course content
Programming Section
Complete the following programming questions by writing a Java program. Ensure that
you are submitting in the correct format by reading the โ€œLAB FORMATTING DOCUMENTโ€ that
is posted on Brightspace in the Lab module. You will need to submit a PDF which contains your
source code (as text) as well as a screenshot of the programโ€™s execution. In windows, you can
use Shift+WindowsKey+S to take a screenshot of your output. Formatting deductions may be
applied if this is not followed. If you have any questions about formatting, please contact the lab
instructor.
Q1 - Programming (2 marks)
โ— Write a program to calculate the mean and standard deviation for a set of user-entered
double values.
โ—‹๐‘š๐‘’๐‘Ž๐‘› = ๐‘ ๐‘ข๐‘š ๐‘œ๐‘“ ๐‘Ž๐‘™๐‘™ ๐‘ฃ๐‘Ž๐‘™๐‘ข๐‘’๐‘ 
๐‘›๐‘ข๐‘š๐‘๐‘’๐‘Ÿ ๐‘œ๐‘“ ๐‘ฃ๐‘Ž๐‘™๐‘ข๐‘’๐‘  (๐‘›)
โ—‹๐‘ ๐‘ก๐‘Ž๐‘›๐‘‘๐‘Ž๐‘Ÿ๐‘‘ ๐‘‘๐‘’๐‘ฃ๐‘–๐‘Ž๐‘ก๐‘–๐‘œ๐‘› = ๐‘ ๐‘ข๐‘š ๐‘œ๐‘“ ๐‘ ๐‘ž๐‘ข๐‘Ž๐‘Ÿ๐‘’๐‘ 
๐‘›
โ—‹๐‘ ๐‘ข๐‘š ๐‘œ๐‘“ ๐‘ ๐‘ž๐‘ข๐‘Ž๐‘Ÿ๐‘’๐‘  = ((๐‘ฅ1)2+ (๐‘ฅ2)2+ ยทยทยท + (๐‘ฅ๐‘›)2)โˆ’ ๐‘ ๐‘ข๐‘š2
๐‘›
โ—‹
โ— Input will begin and end as outlined in the output example.
โ— Submit screenshots of output with the following example sets:
โ—‹ 27, 81, 45, 13, 97, 22
โ—‹ 27.8, 81.2, 45.7, 13.9, 97.3, 22.1
โ—‹ Your student number, separated into 5 values
โ–  Example: #122334455 = 1, 22, 33, 44, 55
Output Example:
pf3

Partial preview of the text

Download Labs and exercises for java and more Exercises Computer Science in PDF only on Docsity!

COSC1046 Lab 3 - Loops and Methods

Note: you can only use concepts covered up to and including Module 3, Unit 3 of the course content

Programming Section

Complete the following programming questions by writing a Java program. Ensure that you are submitting in the correct format by reading the โ€œLAB FORMATTING DOCUMENTโ€ that is posted on Brightspace in the Lab module. You will need to submit a PDF which contains your source code (as text) as well as a screenshot of the programโ€™s execution. In windows, you can use Shift+WindowsKey+S to take a screenshot of your output. Formatting deductions may be applied if this is not followed. If you have any questions about formatting, please contact the lab instructor. Q1 - Programming (2 marks) โ— Write a program to calculate the mean and standard deviation for a set of user-entered double values. โ—‹ ๐‘š๐‘’๐‘Ž๐‘› = ๐‘ ๐‘ข๐‘š ๐‘œ๐‘“ ๐‘Ž๐‘™๐‘™ ๐‘ฃ๐‘Ž๐‘™๐‘ข๐‘’๐‘  ๐‘›๐‘ข๐‘š๐‘๐‘’๐‘Ÿ ๐‘œ๐‘“ ๐‘ฃ๐‘Ž๐‘™๐‘ข๐‘’๐‘  (๐‘›) โ—‹ ๐‘ ๐‘ก๐‘Ž๐‘›๐‘‘๐‘Ž๐‘Ÿ๐‘‘ ๐‘‘๐‘’๐‘ฃ๐‘–๐‘Ž๐‘ก๐‘–๐‘œ๐‘› = ๐‘ ๐‘ข๐‘š ๐‘œ๐‘“ ๐‘ ๐‘ž๐‘ข๐‘Ž๐‘Ÿ๐‘’๐‘  ๐‘› โ—‹ ๐‘ ๐‘ข๐‘š ๐‘œ๐‘“ ๐‘ ๐‘ž๐‘ข๐‘Ž๐‘Ÿ๐‘’๐‘  = ((๐‘ฅ 1

2

  • (๐‘ฅ 2

2

  • ยทยทยท + (๐‘ฅ ๐‘›

2 ) โˆ’ ๐‘ ๐‘ข๐‘š^2 ๐‘› โ—‹ โ— Input will begin and end as outlined in the output example. โ— Submit screenshots of output with the following example sets: โ—‹ 27, 81, 45, 13, 97, 22 โ—‹ 27.8, 81.2, 45.7, 13.9, 97.3, 22. โ—‹ Your student number, separated into 5 values โ–  Example: #122334455 = 1, 22, 33, 44, 55 Output Example:

Q2 - Programming (2 marks) โ— Write a program containing a method that checks to see if a String is a valid password. The password will be valid given the following requirements: โ— In the main method, you should call the password method at least 3 times. โ—‹ The first time, test it with your full name. โ—‹ The second time, test it with your first name + the last 4 digits of your student number + a symbol of your choice. โ—‹ Print the results of both tests to the console. โ— In the third call, you should accept a password from the user and report if it is valid. Output Example: