You are on page 1of 10

1

HIRANANDANI FOUNDATION SCHOOL, THANE


COMPUTER APPLICATION
ASSIGNMENT 2

2021-22
TERM 2

Name: Shifa Mariyam


Class/Div: IX-G
Roll No: 17
2

INDEX
Content Page Number
Section A 3
Question 1 3
Section B 4
Question 2 4
Question 3 7
Question 4 9

Teacher’s Signature:______________
3

Section A:
Answer all the questions.

Question 1

(a)Which of the following is a conditional statement? [1]


1) if
2) goto
3) for
4) none

Ans- 1) if

(b)What is of the significance break statement? [1]


Ans- The break statement is used at the end of each case which acts as the
case terminator. As soon as the break is encountered, the control is
forced to move out of the switch block.
(c) What is difference between / and % operator? [1]
Ans- / is used for division while % is used to find the remainder.
(d) Differentiate between if and switch statement. [1]
Ans-
If statement Switch statement
This statement checks the condition In a switch case statement, a number
first. If the condition is true then the of blocks are created under different
next statement is executed otherwise it cases. A particular case is executed
is ignored. based on the given value (user’s
choice) of control variable passed as
an argument to the switch() statement.

(e) Rewrite the following condition without using logical operators:


if ( a>b || a>c )
System.out.println(a); [1]
Ans- int a;int b,c;
int t=a greater than b?a greater than c?a:c;
System.out.println(t);
4

Section B:
Answer all the questions

Question 2
Given below is a hypothetical table showing rates of Income Tax for male citizens below the
age of 65 years:

Taxable Income (TI) in Income Tax in


Does not exceed 1,60,000 Nil
Is greater than 1,60,000 and
less than or equal to 5,00,000 (TI – 1,60,000) * 10%
Is greater than 5,00,000 and
less than or equal to 8,00,000 [ (TI – 5,00,000) *20%] + 34,000
Is greater than 8,00,000 [ (TI – 8,00,000) *30%] + 94,000
Write a program to input the age, gender (male or female) and Taxable Income of a person. If
the age is more than 65 years or the gender is female, display “wrong category*. If the age is
less than or equal to 65 years and the gender is male, compute and display the Income Tax
payable as per the table given above. [15]

Input:-
//to calculate and display Income Tax
import java.util.*;
public class Income_Tax
{
public static void main(String args[])
{
int age,ti;
char g;
double tax=0.0;
Scanner in=new Scanner(System.in);
System.out.println("Enter gender 'M' for male, 'F' for female");
g=in.next().charAt(0);
System.out.println("Enter age of the person");
age=in.nextInt();
System.out.println("Enter taxable income");
ti=in.nextInt();
if((age<=65)&&(g=='M'))
{
5

if(ti<=160000)
tax=0.0;
if(ti>160000 && ti<=500000)
tax=(ti-160000)*10/100;
if(ti>500000 && ti<=800000)
tax=((ti-500000)*20/100)+34000;
if(ti>800000)
tax=((ti-800000)*30/100)+94000;
System.out.println("*****Details of the Tax Payer*****");//the following statements
will print the details of the payer
System.out.println("Gender of the tax payer:"+g);
System.out.println("Age:"+age);
System.out.println("Taxable Income = Rs."+ti);
System.out.println("Income tax = Rs."+tax);
}
else
{
System.out.println("Wrong category!!");//these statements will output if the
conditions of the if statement aren't met
System.out.println("No calculation of Income Tax!!");
}
}
}
Variable-Description Table
Variable Description
age Age
g Gender
ti Taxable income
tax Income tax

Output:-
6

Enter gender 'M' for male, 'F' for female


M
Enter age of the person
36
Enter taxable income
165000
*****Details of the Tax Payer*****
Gender of the tax payer:M
Age:36
Taxable Income = Rs.165000
Income tax = Rs.500.0
7

Question 3
A Mega Shop has different floors which display varieties of dresses as mentioned
below:
Ground floor : Kids Wear
First floor : Ladies Wear
Second floor : Designer Sarees
Third Floor : Men's Wear
The user enters floor number and gets the information regarding different items of the Mega
shop. After shopping, the customer pays the amount at the billing counter and the shopkeeper
prints the bill in the given format:
Name of the Shop: City Mart
Total Amount:
Visit Again!!
Write a menu driven program to perform the above task as per the user's choice. [15]

public class city_mart


{
public void main()
{
Scanner in=new Scanner(System.in);
int floor;
System.out.println("1. Ground floor");
System.out.println("2. First floor");
System.out.println("3. Second floor");
System.out.println("4. Third floor");
System.out.print("Select a floor: ");
floor = in.nextInt();
boolean isFloorValid = true;
switch (floor)
{
case 1:
System.out.println("Kids Wear");
break;
case 2:
System.out.println("Ladies Wear");
break;
case 3:
System.out.println("Designer Sarees");
break;
case 4:
System.out.println("Men's Wear");
break;
default:
isFloorValid = false;//this will print if a floor number which doesn't exist is entered
System.out.println("Incorrect Floor");
break;
}
System.out.println("Enter bill amount");
double amt = in.nextDouble();
8

//the following statements will display details of the City Mart, the amount and a parting
message
System.out.println("Name of the Shop: City Mart");
System.out.println("Total Amount: " + amt);
System.out.println("Visit Again!!");
}
}
Variable-Description Table
Variable Description
floor Floors of the shop(1-4)
isFloorValid Checks whether the floor is within the range
of 1-4. If false, it displays “Incorrect Floor”
amt Displays the bill amount

Output:-
1. Ground floor
2. First floor
3. Second floor
4. Third floor
Select a floor: 2
Ladies Wear
Enter bill amount
2000
Name of the Shop: City Mart
Total Amount: 2000.0
Visit Again!!
9

Question 4
Using a switch case statement, write a menu driven program to convert a given temperature
from Fahrenheit to Celsius and vice-versa. For an incorrect choice, an appropriate message
should be displayed.
Hint: c = 5/9*(f-32) and f=1.8*c+32 [15]

Input:-
//program to covert temperature from farenheit to celcius scale and vice versa
import java.util.*;
public class temperature
{
public void main()
{
Scanner in= new Scanner(System.in);
System.out.println("Chose 1 or 2 depending on the conversion");
System.out.println("1. To convert from Fahrenheit to Celsius");
System.out.println("2. To convert from Celsius to Fahrenheit");
int choice = in.nextInt();
double f,c;
switch (choice)
{
case 1://executed if temperature is given in Fahrenheit
System.out.print("Enter temperature in Fahrenheit:");
f= in.nextDouble();
c= 5/9*(f-32);
System.out.println("Temperature in Celsius: "+c);
break;
case 2://executed if temperature is given in Celsius
System.out.print("Enter temperature in Celsius:");
c= in.nextDouble();
f= 1.8*c+32;
System.out.println("Temperature in Fahrenheit: "+f);
break;
default://executed if temperature is given in an invalid unit
System.out.println("Incorrect choice");
break;
}
}
}
Variable-Description Table
Variable Description
choice To check whether the given unit is valid
f Fahrenheit
c Celsius
10

Output:-
Chose 1 or 2 depending on the conversion
1. To convert from Farenheit to Celsius
2. To convert from celsius to Farenheit
2
Enter temperature in Celsius:100
Temperature in Farenheit: 212.0

You might also like