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

CS114 - Introduction To Programming For Engineers: Lab 02 - B - October 9, 2015

This document provides instructions for Lab 02B in CS114 - Introduction to Programming for Engineers. It outlines: 1. Instructions for setting up and saving Java files for the lab questions. Files are to be saved in a specific directory and format. 2. Lab rules prohibiting collaboration and use of phones. Students must see TAs for help and sign an attendance sheet. 3. Grading criteria focusing on style, indentation, naming conventions, and comments. 4. Details of three programming questions - calculating formulas based on input number, determining if numbers meet "near/far" criteria, and optimizing chocolate bar packaging based on package size and available bars. Sample runs are provided.

Uploaded by

Elif Duman
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)
38 views3 pages

CS114 - Introduction To Programming For Engineers: Lab 02 - B - October 9, 2015

This document provides instructions for Lab 02B in CS114 - Introduction to Programming for Engineers. It outlines: 1. Instructions for setting up and saving Java files for the lab questions. Files are to be saved in a specific directory and format. 2. Lab rules prohibiting collaboration and use of phones. Students must see TAs for help and sign an attendance sheet. 3. Grading criteria focusing on style, indentation, naming conventions, and comments. 4. Details of three programming questions - calculating formulas based on input number, determining if numbers meet "near/far" criteria, and optimizing chocolate bar packaging based on package size and available bars. Sample runs are provided.

Uploaded by

Elif Duman
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

CS114 - Introduction to Programming for Engineers

Lab 02 – B – October 9, 2015

ATTENTION:
 Using JCreator, from the "File" menu, click "New" --> "File", select either "Empty Java File" or "Main
Class". Do not create a project. Save the file in in "H:" drive or "D:\Temp" directory. Do not save on
the Desktop!
 Java source file names will be Lab02B_Q1_yourLastName.java, Lab02B_Q2_yourLastName.java
and Lab02B_Q3_yourLastName.java. Do not use special Turkish characters in the file name.
 Upload the Java program source file (.java file) to UNILICA.
 Do not put the file in a zip or other compressed file.

LAB RULES:
1. You are allowed to refer to your lecture notes and textbooks during lab sessions. But, you are not
allowed to talk or exchange any form of information with your classmates. Any form of collaboration
is forbidden. You shall not discuss with your classmates how to solve the problem (either actual code
or the pseudo code). If you have any questions please consult the TAs and tutors.
2. Use of cellular phones during lab session is forbidden.
3. When you are done ask your TA to come by and s/he will ask you questions on the assignment and
have you sign the attendance sheet.
4. When you are finally done, please leave the class in a silent and prompt manner and do not disturb
others who are working on the assignment.

GRADING:
1. Points will be taken off if you do not name your files as specified
2. Part of the points for each question will be based on good style: correct indentation, good use of white
space, aligning of parenthesis, and statement blocks, consistent use of naming conventions.
3. Part of the points for each question will be based on comments

Examine the sample runs carefully. Your program should produce exactly the same outputs.
[Q1 30 points] Write a Java program (Lab02B_Q1_lastname.java) that inputs a number(real) from the user. Based
on the number input, calculate the result according to the following:

Inputs: Formula:
Number is greater than or equal to 8 √𝑛𝑢𝑚2 /3
Number is between 4 and 8 (exclusive) 𝑒 𝑛𝑢𝑚 − 8
Number is less than or equal to 4 𝑛𝑢𝑚
𝑛𝑢𝑚 + 20

Input: 9
Result: 5.20

Input: 7
Result: 1088.63

Input: -5
Result: -0.33
Note: you can use Math.sqrt(num) to calculate the square root of a number, Math.exp(num) returns enum and
Math.pow(num, power) to calculate a number to a give power.

[Q2 30 points] Write a Java program(Lab02B_Q2_lastname.java) that does the following. Given three integer
values x,y and z, result is true if one of y or z is "far" (differing from a by at least 2), while the other is "near", differing
from both other values by no more than 1. Otherwise the result is false. Note: use Math.abs (num) to compute the
absolute value of a number.

Sample Runs:
Enter 3 numbers: 2 5 3
The numbers meet the near/far criteria: false

Enter 3 numbers: 7 8 9
The numbers meet the near/far criteria: true

Enter 3 numbers: 9 8 7
The numbers meet the near/far criteria: true

Enter 3 numbers: 9 8 9
The numbers meet the near/far criteria: false
[Q3 40 points] Write a Java program (Lab02B_Q3_lastname.java) to meet the following requirements. You are
trying to determine the most efficient way to package chocolate bars, by weight. There are two sized bars, small (1kg)
and large (7kg). The user will input the size of the package required, and the number of small and large bars available.
Your program must determine how many of the small bars will be included in the package. The rules are as follows:

a. The package must be full.


b. Always use the large bars before using any small bars.
c. If it is not possible to fill the package using the quantity of large and small bars given output a meaningful
message to the user.
d. The input package size must be greater than 7. If the package size entered is too small, output a message to
the user notifying them of an invalid package size.

Run your program several times, using the inputs below. Check carefully to make sure you see the expected output.

Sample Runs:

Package size, number of small, number of large: 6 3 3


The package must be larger than 7kg

Package size, number of small, number of large: 15 4 3


Small Bars needed: 1 for 15kg package

Package size, number of small, number of large: 12 8 1


Small Bars needed: 5 for 12kg package

Package size, number of small, number of large: 21 5 4


Small Bars needed: 0 for 21kg package

Package size, number of small, number of large: 17 5 1


Error - insufficient bars to complete the package

Package size, number of small, number of large: 9 4 3


Small Bars needed: 2 for 9kg package

Package size, number of small, number of large: 10 2 3


Error - insufficient bars to complete the package

You might also like