You are on page 1of 3

COMSATS University Islamabad

Department of Computer Science


Programming Fundamentals (CSC103) – BCT
Class Assignment – 2 (CLO-2)

Due Date: Thursday 2nd, 2023 (11:45 PM)

Instructions
Assignment document must also contain JAVA source code along with output.

You must follow proper JAVA naming convention for identifiers and properly document your
source code

Name of the Assignment document file should be your Registration Number. E.g.
FA21BCS01.docx / FA21BCS01.pdf

Plagiarism: Plagiarism is not allowed. If found plagiarized, zero marks will be awarded in the
assignment.
COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103) – BCT
Class Assignment – 2 (CLO-2)
Note: All Questions should be implemented using functions.

Question – 1: ______
An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also a
prime. For example, 17 is a prime and 71 is a prime, so 17 and 71 are emirps. Write a
program that displays the first 100 emirps.

Sample output for first 20 numbers:

13 17 31 37 71 73 79 97 107 113
149 157 167 179 199 311 337 347 359 389

Question – 2: ______
You are required to create a java program that facilitates the user to calculate the area of three
geometrical objects: Circle, Rectangle and Triangle. The user should be presented with a menu to
choose an option for area calculation. The user may enter ‘c’ for Circle, ‘r’ for Rectangle and ‘t’
for Triangle. Based on user choice the corresponding function of area should be called and result
should be returned.
The methods for area calculation must be implemented as overridden methods. The following
formulas should be used for calculating area of geometric shapes.
Area of circle = Area = π * r^2
Area of Triangle = ½ × b × c × sin(α)
Area of Rectangle = length * breadth

Question – 3: ______
Create a function that returns the percentage of five marks. In the main function, determine
whether the percentage represents fail status or pass status.
Note: you need to design the function signature yourself.

Question – 4: ______
Write a function that accepts a decimal integer and displays its corresponding binary value. Don’t
use Java’s Integer.toBinaryString(int) in this program.

Note: Call the function from main.

Question – 5: ______
The colors red, yellow and blue are known as the primary colors because they cannot be made by
mixing other colors. When you mix two primary colors, you get a secondary color, as shown
here:
When you mix red and blue, you get purple.
When you mix red and yellow, you get orange.
COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103) – BCT
Class Assignment – 2 (CLO-2)
When you mix blue and yellow, you get green.
Write a program that prompts the user to enter the first letter of names of two primary colors to
mix. If the user enters anything other than “r,” “b,” or “y,” the program should display an error
message. Otherwise, the program should change textcolor to that color displays the name of the
secondary color that results. Implement it using if\else structure and then switch structure.

Question – 6: ______
The controversial issue of global warming has been widely publicized by the film “An Inconvenient
Truth,” featuring former Vice President Al Gore. Mr. Gore and a U.N. network of scientists, the
Intergovernmental Panel on Climate Change, shared the 2007 Nobel Peace Prize in recognition of
“their efforts to build up and disseminate greater knowledge about man-made climate change.”
Research both sides of the global warming issue online (you might want to search for phrases like
“global warming skeptics”). Create a five-question multiple choice quiz on global warming, each
question having four possible answers (numbered 1–4). Be objective and try to fairly represent both
sides of the issue. Next, write an application that administers the quiz, calculates the number of
correct answers (zero through five) and returns a message to the user. If the user correctly answers
five questions, print “Excellent”; if four, print “Very good”; if three or fewer, print “Time to brush
up on your knowledge of global warming,” and include a list of some of the websites where you
found your facts.

You might also like