Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Student Name: Uzma Siddiqa

Student number: 209637130

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

Good Evening Maria! Nice to meet you

Answer 1:

Code:
import java.util.Scanner;
public class Concatenation {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner input= new Scanner(System.in);

String str1 = "Good Evening ";


String str2 = "! Nice to meet you";
String sname= " ";

System.out.println("What's your name?");


sname =input.next();

System.out.println(" " +str1+sname+str2);

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 {

public static void main(String[] args) {


// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);


double number,radix;
double calLog=0;
System.out.print("Enter any number: ");
number = input.nextDouble();
System.out.print("Enter radix's value: ");
radix = input.nextDouble();
calLog=Math.log(number)/Math.log(radix);

System.out.println("The result is : "+ calLog);


}

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 {

public static void main(String[] args) {


// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);


double x,y,numbervalue,Decimalvalue;
System.out.println("Enter a two digit number:");
numbervalue= input.nextDouble();

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.)

Week1 Week2 Week3 Week4 Avg Sale Net Profit


January 1001.56 1000.60 1100.02 1015.62 1029.45 00.00%
Feb 1010.11 1210.01 1101.10 1111.09 1108.08 7.64%

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.

You might also like