Professional Documents
Culture Documents
Student Name: Uzma Siddiqa Student Number: 209637130: Summative Assessment-2
Student Name: Uzma Siddiqa Student Number: 209637130: Summative Assessment-2
SUMMATIVE ASSESSMENT-2
Q1. Write a program that accepts the name of a user and concatenates it with two strings; s1= “Good
Evening” and s2=” ! Nice to meet you”. A sample output is given below
Answer 1:
Code:
import java.util.Scanner;
public class Concatenation {
Output:
What's your name?
Uzma
Good Evening Uzma! Nice to meet you
Q2. Write a program that takes a number and a radix as input, and then calculates log of that number
in the given radix. The formula for calculating log in a given radix is :
log e (number)
log radix ( number )=
log e (radix)
Answer 2.
Code:
import java.util.Scanner;
public class NumberandRadix {
Output:
Enter any number: 30
Enter radix's value: 15
The result is : 1.2559580248098154
Q3. Excess three code is an encoding scheme that has digits starting from 3 onwards. This
means that there are no digits less than 3. Note that the decimal digits will be up to 9.
Following are some examples of excess-3 code .
Digit Excess 3 code Binary value of excess-3 code
0 3 0011
1 4 0100
2 5 0101
3 6 0110
4 7 0111
5 8 1000
Write a program that accepts a 2 digit number in excess-3 encoding and generates a decimal
equivalent. Note that every digit of user input is examined, from right to left.
Answer 3.
Code:
import java.util.Scanner;
public class ExcessThreeCode {
x=numbervalue %10;
y = numbervalue/10;
Decimalvalue=(x-3)+(y-3)*10;
System.out.println(Decimalvalue);
Output:
Enter a two digit number:
34
4.9999999999999999
Q4. Write a program that takes the average sales per week as input from user and calculates average
sales per month for 4 months and then prints the next profit compared to the first month and roundup
the value to have a precision of 2 digits after the decimal point. Use format specifiers to generate the
following output ( Note that the columns are separated by 5 digits and there can be maximum 2 digits
after the decimal point; Don’t print the month name or week numbers etc.)
Q5) Write a program to calculate components of vector Á=4 units if it has an angle θ=30° . Note that
the components vectors are given by (r x , r y ¿ = ¿. Convert degrees to radians if necessary.