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

Cmps201 Lab 2

This document outlines 7 questions for a computer science lab assignment. The questions cover topics like conditional execution, string manipulation, and data types. They involve writing Java programs that check triangle properties based on side lengths, determine triangle type, perform math operations on digit strings, calculate day of the year from month and date, determine if a language is compiled or interpreted, identify file types from extensions, and solve an exercise on Practice-It about calculating area. Students are instructed to attempt all questions and submit their work by the deadline.

Uploaded by

haladaher5555
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)
37 views3 pages

Cmps201 Lab 2

This document outlines 7 questions for a computer science lab assignment. The questions cover topics like conditional execution, string manipulation, and data types. They involve writing Java programs that check triangle properties based on side lengths, determine triangle type, perform math operations on digit strings, calculate day of the year from month and date, determine if a language is compiled or interpreted, identify file types from extensions, and solve an exercise on Practice-It about calculating area. Students are instructed to attempt all questions and submit their work by the deadline.

Uploaded by

haladaher5555
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

American University Of Beirut

Department of Computer Science


CMPS201 - LAB 2

Deadline: Friday Midnight Fall 2023 Date: September 11, 2023

Attempt All questions


Question 1 Triangle
Topics: Conditional Execution
Write a program Triangle.java that takes three floating point numbers as command line
arguments and checks whether these numbers can be the lengths of the sides of a valid
triangle. The input is valid if the sum of any two sides is greater than the third side. If
the input is valid the program should p also compute and print the area of the triangle. The
area of a triangle sides are s1 , s2 , s3 is s(s − s1 )(s − s2 )(s − s3 ) where s = (s1 + s2 + s3 )/2
Question 2 Triangle Type
Topics: Conditional Execution
Now, modify the first exercise to determine if the triangle is right, isosceles, or equilateral
triangle, a triangle can be isosceles and right in the same time. In this exercise you are not
allowed to pass over each condition more than once, i.e. you cannot check if a triangle is
isosceles or right more than once.

Sample Runs:
Input sides of triangle: 3 4 5
Triangle is a right triangle

Input sides of triangle: 2 2 2


Triangle is an equilateral triangle

Input sides of triangle: 1 2 3


Triangle is invalid triangle

Question 3 Sum Digits


Part a: In this exercise, you have to write a Java program that takes a 3 digits integer from
the user and prints the sum of all its digits. You are not allowed to convert the integer to
a String.
Sample Run:
Please enter a 3 digits number: 451
Sum of digits: 10

Part b: in this part of the exercise, you have to take a 3 digits number from the user, but
now you have to print the multiplication of all digits.
Sample Run:
Please enter a 3 digits number: 451
Multiplication of digits: 20

Question 4 Day of the Year


In this exercise you have to ask the user to enter a day of a year and a month, then you
have to print which day of the year is it.
Sample Run:
Please enter month: April
Please enter day: 4
April 4 is the day 94 of the year

Question 5 Compiled or Interpreted?


Topics: Conditional Execution
Write a program that prompts the user to enter the name of a programming language and
states some info about this language, for simplicity use the table below as reference for the
used languages (Feel free to add more languages if you want). If the language is compiled,
you have to state what does the compilation process produce. Make your code as efficient
as possible, use nested if/else statements and logical operators when needed to achieve
that.
Sample Runs:
Programming language: Java
Java is compiled, the compilation process produces byte-code.

Programming language: Python


Python is interpreted, it can be run without compilation.

Language Compiled / Interpreted What is produced


Java Compiled Byte-code
Python Interpreted
C/C++ Compiled Machine code / Object File
JavaScript Interpreted
PHP Interpreted
Go Compiled Machine code

Question 6 Type of a File


Topics: String Manipulation
Write a program that prompts the user to enter the name of a file and determines its type.
Limit these types to the following ones:
Extension Type
jpg / jpeg / png Image
mp3 Audio
txt Text File
java Java Code
cpp C Code
Make sure to handle upper and lower case without adding any complexity to your code.

Sample Runs:
Enter the name of a file: test.txt
The file type is txt

Enter the name of a file: image.jpg


The file type is jpg

Enter the name of a file: code.java


The file type is java

Page 2
Enter the name of a file: music.mp3
The file type is mp3

Question 7 Practice-It
Topics: All Topics
Solve the following exercise on practice it: University of Washington CSE 142 (CS1) / Lab
4 (ifelse, Scanner, and return) / area.
Make sure to create an account on practice-it first.

Best wishes

Page 3

You might also like