programming fb project
DESCRIPTION
programming 1TRANSCRIPT
-
Pre-assessment 2.4 for LO8, LO9, LO10, LO11, LO12, and LO13
Part 1. Directions: Read each statement carefully. Write the letter of the correct answer on the
space provided before the number (5 points).
1. It is a location in a computer memory that is used to store values such as numbers
and text and usually change as the program execute.
a. Variable b. Primitive Date Types
2. These are predefined by Java Language and usually named by a keyword.
a. Variable b. Primitive Date Types
3. It is a symbol used to denote concatenating a string.
a. Plus sign (+) b. Dollar sign ($)
4. A data type that represents two states: true or false.
a. Char b. Boolean
5. A data type that represents a single Unicode character. It must have its literal
enclosed in single quotes ( ).
a. String b. character (char)
Part 2. Directions: What data type (int, double, or string) is appropriate for storing each of the
following values? Write your answer on the space before the number (10 points)
1. A product number
2. The amount of interest on a loan, such as 10%
3. The price of a CD
4. The name of your best friend
5. The number of books you own
6. The address of your school
7. The area of a circle
8. The title of a book
9. Your grade in Math
10. The number of your subjects
-
Self-check 2.4
Part 1. Directions: Read each statement carefully. Write the letter of the correct answer on the
space provided before the number (5 points).
1. It is a location in a computer memory that is used to store values such as numbers
and text and usually change as the program execute.
b. Variable b. Primitive Date Types
2. These are predefined by Java Language and usually named by a keyword.
b. Variable b. Primitive Date Types
3. It is a symbol used to denote concatenating a string.
b. Plus sign (+) b. Dollar sign ($)
4. A data type that represents two states: true or false.
b. Char b. Boolean
5. A data type that represents a single Unicode character. It must have its literal
enclosed in single quotes ( ).
b. String b. character (char)
Part 2. Directions: What data type (int, double, or string) is appropriate for storing each of the
following values? Write your answer on the space before the number (10 points)
1. A product number
2. The amount of interest on a loan, such as 10%
3. The price of a CD
4. The name of your best friend
5. The number of books you own
6. The address of your school
7. The area of a circle
8. The title of a book
9. Your grade in Math
10. The number of your subject
-
Part 3. Directions: Given the table below, declare the following variables with the
corresponding data types and initialization values. Output to the screen the variable names
together with the values.
Variable name Data type Initial value
number integer 10
letter character A
result boolean True
str String Hello
The following should be the expected screen output,
1. Number = 10;
2. letter = a;
3. result = True;
4. String = (Hello);
Part 4. Trace the output of the following statements:
1. Program 1:
System.out.print(Java);
System.out.print(Programming);
Output: Java Programming
2. Program 2:
System.out.println(Java);
System.out.println(Programming);
Output: Java
Programming
-
Pre-assessment 2.5 for LO14, LO15, LO16, LO17, LO18, and LO19
Part 1. Directions: Answer the following:
1. The order in which the operations should be performed.
a. Data Types b. Operator Precedence
2. Use to perform calculations with values in your programs.
a. Arithmetic Operators b. Logical Operators
3. This arithmetic operator is used to add values.
a. + b.
4. This arithmetic operator that computes the remainder by dividing the dividend from the
divisor.
a. / b. %
5. A value used on either side of an operator is called ________
a. operant b. operand
6. Increment and decrement operators increase and decrease a value stored in a number
variable by _______.
a. 0 b. 1
7. It is a pre-increment operator
a. ++i b. i++
Part 2. Given the following expressions, re-write them by writing some parenthesis based on
the sequence on how they will be evaluated.
average = score1 + score2 + score3 / 3
Answer: int average = (score1 + score2 + score3 / 3);
result = 3 * 10 * 2 / 15 2 + 4
Answer: int result = (3 * 10 * 2 / 15 2 = 4);
Part 3. Simulate the result. Write your answer on the space provided.
Condition Result
3 * 6 *4 72
12 + 10 + 20 42
44 - 23 21
55 % 555 5
63 / 8 7
-
Self-check 2.5
Part 1. Directions: Answer the following:
1. The order in which the operations should be performed.
b. Data Types b. Operator Precedence
2. Use to perform calculations with values in your programs.
b. Arithmetic Operators b. Logical Operators
3. This arithmetic operator is used to add values.
b. + b.
4. This arithmetic operator that computes the remainder by dividing the dividend from the
divisor.
b. / b. %
5. A value used on either side of an operator is called ________
b. operant b. operand
6. Increment and decrement operators increase and decrease a value stored in a number
variable by _______.
b. 0 b. 1
7. It is a pre-increment operator
b. ++i b. i++
Part 2. Evaluate the following expressions. Show the solution and display the result on the
space provided. (5 items)
1. 4 + 6 2 * 2
Answer: 6
2. 90 / 9 * 2 + 4 2
Answer: 22
3. ((3 / 3) * 9) 6 + (4 + (2 * 2))
Answer: 11
4. (5 * 5 20) % 25 2 + 3 * 5
Answer: 3
5. 2 % 4 * 2 2 + 6 / 3
Answer: 4
-
Pre-assessment 2.6 for LO20 and LO21
Directions: Answer the following. Write the letter of the correct answer on the space provided.
Escape sequence that:
1. moves the cursor to the beginning of the next line.
a. \n b. \r
2. moves the cursor to the beginning of the current line.
a. \n b. \r
3. Moves the cursor to the next tab stop
a. \t b. \s
4. Prints a back slash character
a. // b. \\
5. Prints a double quotation mark
a. \ b. \
Self-check 2.6
Directions: Answer the following. Write the letter of the correct answer on the space provided.
Escape sequence that:
1. moves the cursor to the beginning of the next line.
b. \n b. \r
2. moves the cursor to the beginning of the current line.
b. \n b. \r
3. Moves the cursor to the next tab stop
b. \t b. \s
4. Prints a back slash character
b. // b. \\
5. Prints a double quotation mark
b. \ b. \
-
Pre-assessment 2.7 for LO22 and LO23
Directions: Read the statement carefully. Write the letter of your choice in the space provided
before the number.
1. A class that makes it easy to pop up a standard dialog box that prompts users for a value
or inform them of something.
a. JOptionPane b. JOptionPaneWindow
2. It is package where JOptionPane can be imported.
a. Javax.swing b. javax.exe
3. It is a method used to convert a string to an integer value
a. parseDouble b. parseInt
4. It is a method used to convert a string to double value.
a. parseDouble b. parseInt
5. The JOptionPane.showInputDialog will display a dialog with a message, a textfield and
________.
a. OK button b. Cancel button
Self-check 2.7
Directions: Read the statement carefully. Write the letter of your choice in the space provided
before the number.
1. A class that makes it easy to pop up a standard dialog box that prompts users for a value
or inform them of something.
b. JOptionPane b. JOptionPaneWindow
2. It is package where JOptionPane can be imported.
b. Javax.swing b. javax.exe
3. It is a method used to convert a string to an integer value
b. parseDouble b. parseInt
4. It is a method used to convert a string to double value.
b. parseDouble b. parseInt
5. The JOptionPane.showInputDialog will display a dialog with a message, a textfield and
________.
b. OK button b. Cancel button
-
Pre-assessment 3.1 for LO1 and LO2
Part 1. Directions. Read each statement carefully, select the letter of the correct answer and
write your answer on the space provided. (7 items)
1. It is a code structure where the statements are executed in sequence, without
branching off in another direction.
a. Sequence structure b. Sequence number c. Decision Structure
2. A control structure that allows different parts of a program to execute depending on
the exact situation.
a. Sequence structure b. Sequence number c. Decision Structure
3. It is a less than operator.
a. > b. <
4. This operator sets one value equal to another
a. = b. ==
5. The operator = (2 * 3)
a. True b. False c. Unpredictable
10. Evaluate the expression: 10.0 + 10.0/1.0 < 10.1
a. True b. False c. Unpredictable
Part 2. Directions: Evaluate the following expression. Write T if the expression is TRUE, write F
if the expression is FALSE. Write your answer on the space provided before the number (10
points)
Where: a = 50 b = 25 c = 15
1. a > b 6. b = b
3. a = b 8. (b + c) == a
4. (b + c) > a 9. c == c
5. c != (a b) 10. b >= (a c)
-
Self-check 3.1
Directions: Read each statement carefully, write TRUE if the statement is correct otherwise
write FALSE. Write your answer on the space provided before the number.
1. The expression op1 == op2 is true if op1 is equal to op2.
2. The expression op1 b 6. b = b
3. a == b 8. (b + c) == a
4. (b + c) > a 9. c == c
5. c != (b a) 10. b >= (c a)
-
Pre-assessment 3.2 for LO3 and LO4
Directions: Read each statement carefully. Select the letter of the correct answer and write on
the space provided before the number.
1. These are logical operators used to combine more than one condition that may be
true or false
a. Short-circuit logical operator b. Logical operator c. Bitwise Logical Operator
2. It is a bitwise logical OR operator
a. & b. | c. ||
3. These are logical operators that manipulate the bits of an integer (byte, short, char,
int, long) value.
a. Short-circuit logical operator b. Logical operator c. Bitwise Logical Operator
4. Looks at two expressions and returns a value of true if both expressions are true.
a. & b. && c. ||
5. Looks at two expressions and returns a value of true if either one-but not both-of
the expressions are true.
a. & b. && c.||
Self-check 3.2
Part 1. Directions: Read each statement carefully, write TRUE if the statement is correct
otherwise write FALSE. Write your answer on the space provided before the number.
1. Logical operator deals with connecting the Boolean values.
2. The operator used for short-circuit logical OR is &&.
3. The operator used for short-circuit logical AND is ||.
Directions: Select the letter of the correct answer and write your answer on the space provided
4. Used to combine more than one condition that may be true or false.
a. Short-circuit logical operator b. Logical operator c. Bitwise Logical operator
5. Manipulate the bits of an integer (byte, short, char, int, long) value.
a. Short-circuit logical operator b. Logical operator c. Bitwise Logical operator
Part 2. Directions: Evaluate the following expression. Write your answer on the space provided
before the number.
Where: a = 50 b = 25 c = 15
1. (a > b) && (a > b) 3. (c < b) && (b > a) 5. c != (a b)
2. (a == b) || (b + c) < c 4. (a < b) || (b > a)
-
Pre-assessment 3.3 for LO5 and LO6
Directions: Read each statement carefully, select the letter of the correct answer and write
your answer on the space provided.
1. How many choices are possible when using a single if-else statement?
a. 1 b. 2 c. 3 d. 4
2. What does the following code fragment displays?
Int sum = 14;
If (sum < 20)
System.out.print(Under);
else {
System.out.print(Over);
System.out.println(the limit);
}
a. Under b. Over c. Under the limit d. Over the limit
3. What does the following code fragment displays?
Int sum = 7;
If (sum > 20)
{
System.out.print(You win);
}
else
{
System.out.println(You lose);
}
System.out.print(the prize.);
a. You win b. You lose c. You win the prize. d. You lose the prize.
4. What does the following code fragment displays?
Int sum = 21;
If (sum != 20)
System.out.print(You win);
else
System.out.print(You lose);
System.out.println(the prize.);
a. You win b. You lose c. You win the prize. d. You lose the prize.
5. In using the switch statement, when the Boolean_expression is true, the program
will ________.
a. Execute a statement b. terminate the program c. hang the program
-
Self-check 3.3
Directions: Read each statement carefully,, select the letter of the correct answer and write your answer
on the space provided.
1. What does the following code fragment displays?
Int height = 10;
If (height =
5. Fill-in the blank, so student with grade greater than or equal to 75 will pass the course.
If (grade ____ )
System.out.println(You passed);
else
System.out.println(Sorry, you failed);
a. < b. == c. != d. >=
-
Part 2. Directions: Write the syntax/form of the following items.
1. If-statement 3. If-else-if statement
2. If-else statement
Pre-assessment 3.4 for LO7 and LO8
Directions: Fill-in the missing syntax of the switch structure flowchart
Switch Statement Flowchart
or
-
8. It is an alternative to the use of the series of nested if statements.
a. If statement b. switch statement c. for statement
9. In the format of the switch statement, the (switch_expression) should be a/an
______expression.
a. Double or String expression c. character expression only
b. Integer or character expression d. String expression only
10. In the switch statements, if none of the cases are satisfied, this block is executed.
a. Default block b. break block c. case block
Self-check 3.3
Input the letter of your choice from: S-Small; M-Medium; L-Large; X-Extra-large and display the
value for each choice. For example.
Choice: S
The size is Small
Algorithm
Int size = 35; Switch (size / 5 ) { case 9: case 10: System.out.println(S); System.out.println(The size is Small); Break; case 8: case 7: System.out.println(M); System.out.println(The size is Medium); Break; case 5: case 6: System.out.println(L); System.out.println(The size is Large); Break; case 3: case 4: System.out.println(X) System.out.println(The size is Extra-large); Break; }
-
Lab 2.7
Based on the algorithm presented, write a Java program to calculate the area of a circle. Assign
an integer values to the variable radius for example int radius = 2. Save the class as
Circle.java.
Algorithm:
1. Read in the radius
2. Compute the area using the following formula:
Area = radius x radius x 3.142
3. Display the area
Write your source codes.
public class Circle
{
public static void main(String[] args)
{
int radius = 2;
double area = 3.142;
area = radius * radius * area;
System.out.println(The area of the circle is + area);
}
}
What is the output of the program?
The area of the circle is 12.568
-
Lab 2.8: Using variables and data types
Write a program that converts pounds into kilograms. Assign appropriate values to the variable in
pounds, converts it to kilograms, and displays the result. Save the class as Weight.java.
[Note: One pound is 0.454 kilograms.]
Write your source codes.
public class Weight {
public static void main(String[] args) {
String Onepound = 0.454 kg;
System.out.println(One pound is = + Onepound); }
}
What is the output of the program?
One pound is = 0.454 kg
Lab 2.9 Using variables and data types
Write a Java program that declares variables to represent the length and width of a room. Assign
appropriate values to the variables for example, length = 20 and width = 15. Then complete and
display the floor space in square feet. Display explanatory text with the value for example, The floor
space is 300 square feet. Save the class as Room.java. [Note: Floor space = length * width.]
Write your source codes.
public class Room {
public static void main(String[] args) {
int length = 30, width = 25, floorSpace = 0;
floorSpace = length * width;
System.out.println(The floor space is + floorSpace); }
}
What is the output of the program?
The floor space is 750
-
Lab 2.10 GETTING THE AVERAGE OF THREE NUMBERS
In this laboratory activity, you will create a program that outputs the average of three numbers.
Let the value of the three numbers be 10, 20 and 45. Save the class as Average.java. The
expected output is,
number1 = 10
number2 = 20
number3 = 45
average is = 25
Write you source codes.
public class Average
{
public static void main(String[] args)
{
int num1 = 10, num2 = 20, num3 = 45;
int average = (10 + 20 + 45) / 3;
System.out.println(The average is + average);
}
}
What is the output of the program?
The average is 25
-
LAB 2.11. Getting the results of the different variables declared using arithmetic operators.
1. Open NetBeans IDE and create a new project and name it as ArithmeticOperators.java.
2. Write your source codes.
public class ArithmeticOperators
{
public static void main(String[] args)
{
int i = 37, j = 42;
double x = 27.475, y = 7.22;
int add1 = (i + j);
double add2 = (x + y);
int subtract1 = (i j);
double subtract2 = (x y);
int multiply1 = (I * j);
double multiply2 = (x * y);
int divide1 = (i / j);
double divide2 = (x / y);
int remainder1 = (i % j);
double remainder2 = (x % y);
double mix1 = (j y);
double mix2 = (i * x);
System.out.println( Variable values. . .);
System.out.println(i = + i);
-
System.out.println(j = + j);
System.out.println(x = + x);
System.out.println(y = + y);
System.out.println(Adding. . .);
System.out.println(i + j = + add1);
System.out.println(x + y = + add2);
System.out.println(Subtracting. . .);
System.out.println(i j = + subtract1);
System.out.println(x y = + subtract2);
System.out.println(Multiplying. . .);
System.out.println(i * j = + multiply1);
System.out.println(x * y = + multiply2);
System.out.println(Dividing. . .);
System.out.println(i / j = + divide1);
System.out.println(x / y = + divide2);
System.out.println(Computing the remainder. . .);
System.out.println(i % j = + remainder1);
System.out.println(x % y = + remainder2);
System.out.println(Mixing types. . .);
System.out.println(j y = + mix1);
System.out.println(i * x = + mix2);
}
}
-
LAB 2.12. Getting the sum of two integers
Write a Java program that reads in two integers and display the sum of the two integers. Save
the class as Sum.java.
Write your source codes.
public class Sum {
public static void main(String[] args) {
int integer1 = -4, integer2 = -25;
int sum = -4 + -25;
System.out.println(The sum of the two integers: + sum); }
}
What is the output of the program?
The sum of the two integers: -29
Lab 2.13
Write a class that displays the following heading on one line:
First Name Last Name Student Number Phone Number
Display your first name, last name, student number and phone number on the second line,
below the appropriate column headings. Save the class as Escape.java.
Write your source codes.
public class Escape {
public static void main(String[] args) {
String FirstName = Rick Azley, LastName = Martin;
Double StudentNumber = 21-9154, PhoneNumber = +63905-1752-472;
System.out.println(\Rick Azley\tMartin\t21-9154\t+63905-1752-472\); }
}
What is the output of the program?
Rick Azley Martin 21-9154 +63905-1752-472
-
Lab 2.14
Using the escape sequences you learned before, write a program that calculates the squares
and cubes of the numbers from 0 to 3 and uses tabs to print the following table of values. Save
the class as Number.java
Number square cube 0 0 0 1 1 1 2 4 8 3 9 27
Write you source codes here.
public class Number
{
public static void main(String[] args)
{
int number1 = 0, number2 = 1, number3 = 2, number4 = 3;
int square1 = 0, square2 = 1, square3 = 4, square5 = 9;
int cube1 = 0, cube2 = 1, cube3 = 8, cube4 = 27;
System.out.println(number\tsquare\t cube);
System.out.println(0\t\t0\t\t0);
System.out.println(1\t\t1\t\t1);
System.out.println(2\t\t4\t\t8);
System.out.println(3\t\t9\t\t27);
}
}
-
Lab 2.15
Write a program that prints a box and a diamond as follows. Save the class as Box.java.
********* * * * * * * * * * * * * * * * * * * * * * ********* *
Write your source codes here.
public class Box
{
public static void main(String[] args)
{
System.out.println(********* *);
System.out.println(* * * *);
System.out.println(* * * *);
System.out.println(* * * *);
System.out.println(* * * *);
System.out.println(* * * *);
System.out.println(********* *);
}
}
-
Lab 2.16: Clearing a Multiple Input Dialog Box
In this lab, you will write, compile and test a class that prints your full name, address and motto
in life in a series of three dialog boxes so that each displays one line of the output in the screen.
Be sure to add comments to your program. Save the class as Student.java.
Write your source codes here.
Input javax.swing.JOptionPane;
public class Student
{
public static void main(String[] args)
{
String first = JOptionPane.showInputDialog(null, Enter your full name, NAME,
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(null, My name is + first, NAME,
JOptionPane.INFORMATION_MESSAGE);
String second = JOptionPane.showInputDialog(null, Enter your address, ADDRESS,
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(null, Your address is +second, ADDRESS,
JOptionPane.INFORMATION_MESSAGE);
String third = JOptionPane.showInputDialog(null, Enter your motto, MOTTO,
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(null, My motto is + third, MOTTO,
JOptionPane.INFORMATION_MESSAGE);
}
}
-
Lab 2.17: Creating a Multiple Input Dialog Box
Using JOptionPane, ask for three words from the user and output those three words on the
screen. Save it as LastThreeWords.java.
Write your source codes here:
Input javax.swing.JOptionPane;
public class LastThreeWords
{
public static void main(String[] args)
{
String word = , word1 = , word2 = ;
word = JOptionPane.showInputDialog(Enter word 1);
word1 = JOptionPane.showInputDialog(Enter word 2);
word2 = JOptionPane.showInputDialog(Enter word 3);
JOptionPane.showMessageDialog(null, msg);
}
}
-
Lab 2.18
Write a Java program that asks the user to enter two numbers using an input dialog and
prints the sum, product, difference and quotient of the two numbers in a message dialog. Save
the class as InputNumber.java.
Write your source codes here:
Import javax.swing.JOptionPane;
public class InputNumber
{
public static void main(String[] args) {
String first = JOptionPane.showInputDialog(null, Enter first number, INPUT,
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(null, The first number is + first, OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
String second = JOptionPane.showInputDialog(null, Enter second number, INPUT,
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(null, The second number is + second, OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
int firstInt = Integer.parseInt(first);
int secondInt = Integer.parseInt(second);
JOptionPane.showMessageDialog(null, Sum of the two numbers = +(firstInt + secondInt),
SUM, JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, Product of the two numbers = +(firstInt secondInt),
PRODUCT, JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, Difference of the two numbers = +(firstInt *
secondInt), DIFFERENCE, JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, Quotient of the two numbers = +(firstInt / secondInt),
QUOTIENT, JOptionPane.INFORMATION_MESSAGE); }
}
-
Lab 2.19
Write a Java program that reads a Fahrenheit degree in double from an input dialog box, then
converts it to Celsius and displays the result in a message dialog box. Save the class as
Temperature.java. The formula for the conversion is:
[Note: In java, 5/9 is 0, so you need to write 5.0/9 in the program to obtain the correct result.]
Celsius = (5.0/9) * (Fahrenheit 32)
Write your source codes here:
Import javax.swing.JOptionPane;
public class Temperature
{
public static void main(String[] args)
{
int formula = 32;
double Celsius = 5.0/9;
String fahrenheit = JOptionPane.showInputDialog(null, Enter a Fahrenheit degree), INPUT,
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(null, The Fahrenheit that you entered is + Fahrenheit,
OUTPUT, JOptionPane.INFORMATION_MESSAGE);
double fahrenheitDouble = Double.parseDouble(fahrenheit);
JOptionPane.showMessageDialog(null, Celsius = +((Celsius) * (fahrenheitDouble Formula)),
OUTPUT, JOptionPane.INFORMATION_MESSAGE);
}
}
-
ACTIVITY/JOB SHEET 3.1 Using Relational Operators
Create a Java program that will display results based on the declared integers: number1 = 50, number2 = 70 and number3 = 100. Use some of
the relational operators to provide Boolean results. Save file as: RelationalBooleanResults.java. The expected output is:
Integers:
number1 = 50
number2 = 70
number3 = 100
Truth Table:
number1 > number2 = False
number1 >= number3 = True
number2 < number1 = False
number2 70), number2 = (50>=100), number3 = (70= number3 = + number2);
System.out.println(number2 < number1 = + number3);
System.out.println(number2
-
ACTIVITY/JOB SHEET 3.2 Using Logical && Operator
Make a Java program that will satisfy the condition set in the scenario presented below using
the logical AND operator.
For college BSIT student to graduate, he or she needs to pass all subjects AND to complete the
capstone project. Using this scenario, let:
Condition 1 = Passed all subjects
Condition 2 = Completed the capstone project
Result: Graduate
Write your source codes here.
public class StudentGraduate
{
public static void main(String[] args)
{
int Subjects = 8, CapstoneProjects = 10;
if (Subjects > 3 && CapstoneProjects >4)
Sytem.out.println(RESULT: Graduate);
else
System.out,pringln(RESULT: Sorry, you cant Graduate);
}
}
What is the output of the program?
RESULT: Graduate
-
Lab 3.3 Using the logical (||) operator
Make a Java program that will satisfy the condition set in the scenario presented below using
the logical OR operator.
For the Computer Clubs event to be approved, the proposal must be signed either be COLLEGE
DEAN OR PROGRAM CHAIR. Using this scenario, let:
Condition1 = Signature of the college Dean
Condition2 = Signature of the Program Chair
Result: Event is APPROVED
Write your source codes here.
public class ComputerClubEvent
{
public static void main(Strimg[] args)
{
int CollegeDeanSignature = 1, ProgramChairSignature = 1;
int (CollegeDeanSignature > 0 || ProgramChairSignature < 0)
System.out.println(RESULT: Event is APPROVED);
else
System.out.println(RESULT: Event is not APPROVED);
}
}
What is the output of the program?
RESULT: Event is APPROVED
-
LAB 3.4 Using logical | Operator
Make a Java program that will satisfy the condition set below using logical NOT operator.
If color is not ORANGE display message You dont belong
Save the class as ColorNotOperator.java.
Write your source code here.
public class ColorNotOperator
{
public static void main(String[] args)
{
int Orange = 30;
if (!(Orange < 31))
System.out.println(\You are belong\);
else
System.out.println(\You dont belong\);
}
}
-
ACTIVITY/JOB SHEET 3.5
Write a Java program application that asks the user to input two numbers. If the first number
entered is greater than the second number, the program should print the message The first
number is greater, else it should print the message The first number is smaller. And if the
two numbers entered are equal, it will display invalid. Save your file as GreaterSmaller.java.
Write your source codes here.
public class GreaterSmaller
{
public static void main(String[] args)
{
if number1 = 25, number2 = 4;
if (number1 > number2)
System.out.println(The first number is greater);
else if (number1 == number2)
System.out.println(Invalid);
else
System.out.println(The first number is smaller);
}
}
What is the output of the program?
The first number is greater
-
ACTIVITY/JOB SHEET 3.6
Create a program that will determine if your input is negative or positive, if your input
data is less than 0 then output should display negative number, otherwise if you input data
that is greater than equal to 0 then output should display positive number. Save the file as
NegativePositive.java.
Write your source codes here.
public class NegativePositve
{
Public static void main(String[] args)
{
int number = -4;
if (number < 0)
System.out.println(negative number);
else if (number >= 0)
System.out.println(Positive number);
}
}
What if the output of the program?
negative number
-
ACTIVITY/JOB SHEET3.7
Write a Java application that asks a user to enter an IQ score. If the score is a number lees than
0 or greater than 200, issue an error message; otherwise, issue an Above average for scores
over 100, Average for score at 100 or Below average for scores under 100. Save the file as
IQ.java.
Write your source codes here.
public class IQ
{
public static void main(String[] args)
{
int IQ = 120;
if (IQ < 0 || IQ > 200)
System.out.println(Above average);
else if (IQ == 100)
System.out.println(Average);
else
System.out.println(Below average);
}
}
What is the output of the program?
Below average
-
ACTIVITY/JOB SHEET 3.8
Write an application that prompts user for two integers and then prompts the user to enter and
option. If the choice is 1, add the two integers, If it is 2, subtract the second integer from the
first. If it is 3, multiply the integers. Display the results of the arithmetic. Save the file as
Calculate.java.
Write your source codes here.
Import javax.swing.JOptionPane;
public class Calculate
{
public static void main(String[] args)
{
int Integer1 = 4, Integer2 = 9;
String choice = JOptionPane.showInputDialog(null, ENTER YOUR CHOICE 1-3, INPUT,
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMesageDialog(null, YOU CHOSED + choice, OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
int intValue = Integer.parseInt(choice);
if (intValue == 1)
JOptionPane.showMessageDialog(null, OUTPUT = + (Integer1 + Integer2), OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
else if (intValue == 2)
JOptionPane.showMessageDialog(null, OUTPUT = + (Integer1 Integer2), OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
else if (intValue == 3)
JOptionPane.showMessageDialog(null, OUTPUT = + (Integer1 * Integer2), OUTPUT,
JOptionPane.INFORMATION_MESSAGE); }
}
-
ACTIVITY/JOB SHEET 3.9
Create a program that will determine if the student score is passed of failed, if the score
is greater that equal to 75 the program should display Passed, buy if the score is less than 75,
the program should display Failed. Save the file as StudentGrade.java.
Write your source codes here.
Import javax.swing.JOptionPane;
public class StudentGrade
{
public static void main(String[] args)
{
String Grade = JOptionPane.showInputDialog(null, ENTER YOUR GRADE, INPUT,
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(null, YOUR GRADE: + Grade, OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
Int intValue = Integer.parseInt(Grade);
If (intValue >= 75)
JOptionPane.showMessageDialog(null, YOU PASSED, OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, YOU FAILED, OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
}
}
-
ACTIVITY/JOB SHEET 3.10
Write a program for furniture company; the program determines the price of a table. Ask the
user to choose 1 for pine, 2 for oak or 3 for mahogany. The output is the name of the wood
chosen as well as the price of the table. Pine table cost Php100, oak tables cost Php250 and
mahogany table cost Php500. If the user enters invalid wood code set the price to 0. Save the
file as Furniture.java.
Write your source codes here.
Import javax.swing.JOptionPane;
public class Furniture {
public static void main(String[] args) {
String Wood = JOptionPane.showInputDialog(null, Enter wood code from 1-3, INPUT,
JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(null, YOU CHOSED + Wood, OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
int intValue = Integer.parseInt(Wood);
int Table1 = 100, Table2 = 250, Table3 = 500;
if (intValue == 1)
JOptionPane.showMessageDialog(null, Pine table cost + Php + Table1, OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
else if (intValue == 2)
JOptionPane.showMessageDialog(null., Oak table cost + Php + Table2, OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
else if (intValue == 3)
JOptionPane.showMessageDialog(null, Mahogany table cost + Php + Table3, OUTPUT,
JOptionPane.INFORMATION_MESSAGE);
}
}
-
Activity/Job Sheet 3.10 Using conditional operator
Write a java program that will display Youre Outstanding if grade is exactly equal to
100, if not display Just Fine. Save file as UsingConditionalOperator.java.
Write your source codes here.
import javax.swing.JOptionPane;
public class UsingConditionalOperator
{
public static void main(String[] args)
{
String number1 = JOptionPane.showInputDialog(Enter Grades);
int number = 0;
number = Integer.parseInt(number1);
If (number = 100)
System.out.println(Youre Outstanding);
else
System.out.println(Just Fine);
}
}
What is the output of the program?