0% found this document useful (0 votes)
16 views

QB - 9th - Comp Lesson 5,6,7

The document discusses input and output in Java programs. It provides questions and answers on topics like the Scanner class, different ways to take input in Java, package imports, errors in programs. It also covers mathematical library methods in Java like Math.sqrt, Math.max, Math.abs etc. Examples of taking user input and performing calculations are given.

Uploaded by

Amazer Suvam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

QB - 9th - Comp Lesson 5,6,7

The document discusses input and output in Java programs. It provides questions and answers on topics like the Scanner class, different ways to take input in Java, package imports, errors in programs. It also covers mathematical library methods in Java like Math.sqrt, Math.max, Math.abs etc. Examples of taking user input and performing calculations are given.

Uploaded by

Amazer Suvam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

CLASS – 9, COMPUTER APPLICATION, QUESTION BANK

Chapter – 5, Input in Java

Q.1) Name the followings.


Ans.1) java.util
Ans.2) sc.next().charAt(0)
Ans.3) java.io
Ans.4) sc.nextDouble()
Ans.5) sc.nextInt()

Q.2) Write down the syntax with reference to Java programming.


Ans.1) int p = Integer.parseInt(br.readLine());
Ans.2) float m = sc.nextFloat();
Ans.3) char d = (char)br.read();
Ans.4) double n = Double.parseDouble(br.readLine());
Ans.5) String wd = br.readLine();
Ans.6) Scanner sc = new Scanner(System.in);

Q.3) Differentiate between.


Ans.1) nextInt() method of Scanner class is used to accept/receive an integer entered through keyboard
during run time and stores in a variable. nextFloat() method of Scanner class is used to receive / accept a
decimal value entered through keyboard during run time and stores in a variable.

Ans.2) Syntax errors occur due to violation of rules and grammar of the language or due to typing
mistakes. These errors are shown during compile time and program does not execute until the errors
are removed. Logical errors occur due to wrong planning in program’s logic by programmer or due to
using wrong method to solve a problem or due to use of wrong operators. These errors are never shown
and program gets executed but shows wrong output.

Q.4) Answer the followings.


Ans.1) Scanner class is present in the java.util package. It contains many methods through which data
can be accepted during runtime. Some of the methods are nextLine(), nextInt(), nextDouble(), etc.

Ans.2) Input can be given in a Java program in the following three ways. They are…
a) By using function arguments
b) By using InputStreamReader class and BufferedReader class
c) By using Scanner class

Ans.3) import keyword is used to include a package in a program. It activates a package and links it with
a program.
Ans.4) A package is a collection of various pre-defined classes. These classes contain various functions
which perform various tasks. In order to use these functions, we need to include the package in our
program. The keyword “import” helps to include a package in a program. Example of packages: java.util
and java.io

Ans.5) class A
{
public static void main(int a)
{
int b = a * a;
System.out.println(“Number = “ + a + “ and its square = “ + b);
}
}

Ans.6) A Diagnostic message indicates that something may be wrong with the program. It is shown by
the compiler. Diagnostical messages detect only syntax errors means there are pre-defined rules in Java
language or syntax of writing statements. If these rules or syntaxes are not followed then, the compiler
can detect it and report these errors during compile time. That’s why only syntax errors can be reported
through Diagnostical messages.

Ans.7) char ch = sc.next().charAt(0);

Ans.8) Run time errors occur due to wrong data given as input during run time or due to incorrect
mathematical operations. These errors are shown during the execution of the program. Example of run
time error is dividing a number by zero.

Ans.9) Syntax error, Logical error and Run time error are the three types of error that may occur during
execution of a program.

Ans.10)
a) Testing is a process in which a program is validated. Testing is complete when all desired
verifications against specifications have been performed. Debugging is a process in which the errors
are removed from the program. Debugging is finished when there are no errors and the program is
ready for execution.

b) Syntax errors occur due to violation of rules and grammar of the language or due to typing mistakes.
These errors are shown during compile time and program does not execute until the errors are
removed. Logical errors occur due to wrong planning in program’s logic by programmer or due to
using wrong method to solve a problem or due to use of wrong operators. These errors are never
shown and program gets executed but shows wrong output.

Q.5) Java programming.


Ans.1)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double L , G, T;
System.out.println(“Enter length and acceleration due to gravity”);
L = sc.nextDouble();
G = sc.nextDouble();
T = 2*22/7.0*Math.sqrt(l/g);
System.out.println(“Time period of a Simple Pendulum = “ + T);
}
}

Ans.2)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double bs, da, hra, pf, gross, net;
System.out.println(“Enter the basic salary”);
bs = sc.nextDouble();
da = 30/100.0 * bs;
hra = 15/100.0 * bs;
pf = 12.5/100 * bs;
gross = bs + da + hra;
net = gross – pf;
System.out.println(“Gross Pay = “ + gross);
System.out.println(“ Net Pay = “ + net);
}
}
Ans.3)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double price, discount, gst, net1, net2;
System.out.println(“Enter the printed price of the digital camera”);
price = sc.nextDouble();
discount = 10/100.0 * price;
net1 = price – discount;
gst = 6/100.0 * net1;
net2 = net1 + gst;
System.out.println(“Net Price = “ + net2);
}
}

Ans.4)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double price, d1, d2, d3;
System.out.println(“Enter the price of the article”);
price = sc.nextDouble();
d1 = 30/100.0 * price;
d2 = 20/100.0 * price;
d3 = 10/100.0 * price;
System.out.println(“Discount of first shopkeeper = “ + d1);
System.out.println(“Discount of second shopkeeper = “ + d2 + “ and “ + d3);
}
}
Ans.5)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double P,T=1,R=5,CI,CII,CIII;
System.out.println("Enter Principal");
P = sc.nextDouble();
CI = (P * Math.pow((1 + R/100),T)) - P;
P = P + CI;
CII = (P * Math.pow((1 + R/100),T)) - P;
P = P + CII;
CIII = (P * Math.pow((1 + R/100),T)) - P;
System.out.println(“First Year Interest = “ + CI);
System.out.println(“Second Year Interest = “ + CII);
System.out.println(“Third Year Interest = “ + CIII);
}
}

Ans.7)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int time, hr, min, sec;
System.out.println("Enter time in seconds");
time = sc.nextInt();
hr = time / 3600;
min = (time % 3600) / 60;
sec = (time % 3600) % 60;
System.out.println(“Total time in seconds = “ + time);
System.out.println(“It is = “ + hr +” Hour “ + min + “ Minutes “ + sec + “ Seconds”);
}
}
Ans.8)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a, b;
System.out.println(“Enter two numbers”);
a = sc.nextInt();
b = sc.nextInt();
a = a +b;
b = a – b;
a = a – b;
System.out.println(“a = “ + a + “ b = “ + b);
}
}

Ans.9)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double P, T=3, R=10, CI, SI, diff;
System.out.println("Enter Principal");
P = sc.nextDouble();
CI = (P * Math.pow((1 + R/100),T)) – P;
SI = P * R * T / 100;
diff = Math.abs(SI – CI);
System.out.println(“Simple Interest = “ + SI);
System.out.println(“Compound Interest = “ + CI);
System.out.println(“Difference = “ + diff);
}
}
Ans.10)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double SP1, SP2, CP1, CP2;
System.out.println("Enter the sale price of first calculator");
SP1 = sc.nextDouble();
System.out.println("Enter the sale price of second calculator");
SP2 = sc.nextDouble();
CP1 = SP1 / (1 + 20/100.0);
CP2 = SP2 / (1 – 20/100.0);
System.out.println(“Cost price of two calculators = “ + (CP1 + CP2));
}
}

Chapter – 6, Mathematical Library Methods

Q.1) Choose the correct answer.


Ans.1) Math.sqrt(a,2)
Ans.2) double
Ans.3) Math.sqrt(a)
Ans.4) Java.Math
Ans.5) 9.99
Ans.6) 3.0

Q.2) Predict the output.


Ans.1) 3.2
Ans.2) – 99.0
Ans.3) 3.5
Ans.4) – 25.5
Ans.5) – 0.0
Ans.6) – 18
Ans.7) – 77.66
Ans.8) – 1.0
Ans.9) 98.0
Ans.10) 66.0

Q.3) Write down the syntax for the followings.


Ans.1) Math.min(p,q)
Ans.2) Math.abs(m)
Ans.3) Math.exp(k)
Ans.4) Math.sqrt(d)
Ans.5) Math.round(b)

Q.4) Predict the return data type of the following functions.


Ans.1) double
Ans.2) double
Ans.3) double
Ans.4) int
Ans.5) double
Ans.6) double

Q.5) Explain the following functions.


Ans.1) Math.random() function returns a decimal number randomly which is greater than 0.0 and
smaller than 1.0.
Ans.2) Math.max() function returns the greater number out of two given numbers.
Ans.3) Math.cbrt() function returns the cube root of a given number.
Ans.4) Math.abs() function returns the absolute value of a given number ignoring its sign.
Ans.5) Math.log() function returns the natural logarithmic value of a given number.

Q.6) Distinguish between.


Ans.1) Math.ceil() and Math.floor()
Math.ceil() function returns a higher or equivalent value of the given number. Ex – Math.ceil(2.4) = 3.0
Math.floor() function returns a lower or equivalent value of the given number. Ex – Math.floor(2.8) = 2.0

Ans.2) Math.round() and Math.rint()


Math.round() function is used to return the round off value of a given number. if the fractional part of a
given number is less than 0.5 then it returns the integer part of that given number otherwise it returns
the next higher integer value. Its return type is int. Ex – Math.round(2.5) = 3
Math.rint() function is also used to return the round off value of a given number. But its return type is
double. If the fractional part of a given number is within 0.0 to 0.5 then it returns the integer part of that
given number in decimal form otherwise it returns the next higher integer number in decimal form.
Ex – Math.rint(2.5) = 2.0 and Math.rint(2.51)=3.0
Q.7) Unsolved Programs.
Ans.1)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a, b, c, d, e;
System.out.println(“Enter three numbers”);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
d = Math.max(a, Math.max(b, c));
e = Math.min(a, Math.min(b, c));
System.out.println(“Greatest = “ + d + “ Smallest = “ + e);
}
}
Ans.2)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double p, b, h;
System.out.println(“Enter the perpendicular and base”);
p = sc.nextDouble();
b = sc.nextDouble();
h = Math.sqrt( p*p + b*b);
System.out.println(“Hypotenuse = “ + h);
}
}
Ans.3)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a;
System.out.println(“Enter a number”);
a = sc.nextInt();
System.out.println(“ Natural Logarithm = “ + Math.log(a));
System.out.println(“ Absolute Value = “ + Math.abs(a));
System.out.println(“ Square root = “ + Math.sqrt(a));
System.out.println(“ Cube root = “ + Math.cbrt(a));
System.out.println(“ Random number = “ + Math.random());
}
}

Ans.4)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double a, b, c, d;
System.out.println(“Enter Physics, Chemistry and Biology marks”);
a = sc.nextDouble();
b = sc.nextDouble();
c = sc.nextDouble();
d = (a + b + c)/3;
System.out.println(“Average mark = “ + d);
System.out.println(“Round off Physics mark = “ + a);
System.out.println(“Round off Chemistry mark = “ + b);
System.out.println(“Round off Biology mark = “ + c);
}
}
Ans.5)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double area, rad;
System.out.println(“Enter area of the circle”);
area = sc.nextDouble();
rad = Math.sqrt((7*area)/22 );
System.out.println(“Radius of the Circle = “ + rad);
}
}

Chapter – 7, Conditional Statements in Java

Q.1) Multiple Choice Question.


Ans.1) a default case
Ans.2) if(a>b) a++; b++;
Ans.3) Relational operators
Ans.4) a is the greatest number
Ans.5) None
Ans.6) Scalene triangle
Ans.7) Relational operator
Ans.8) if
Ans.9) switch case statement
Ans.10) logical error

Q.2) Answer the following questions.


Ans.1) The different ways to manage the flow of control in a program are:
a) Normal flow of control (Sequential)
b) Conditional flow of control (Selection)
c) Iterative / Repetitive flow of control (Iteration / loop)

Ans.2) (a) if else statement (b) switch case statement


Ans.3) (a) The presence of one if statement within another if block is called nested if. The inner if
statement will only be checked when the outer if statement is evaluated to true otherwise not.
if(condition1)
{
if(condition2)
Statement1
else
Statement2

]
else
{
Statement3
}

(b) if else statement is used to check a condition and to execute some statements when the condition is
true and to execute some other statements when the condition is false.
if(condition)
Statement1
else
Statement2
(c) if else if statement is used when more than two actions are to be taken. It checks one condition and it
is true then one action is taken otherwise another condition is checked and if that is true then second
action is taken otherwise next conditions are checked one by one and depending on the result of those
conditions, any one action is taken.
if(condition1)
Action1
else if(condition2)
Action2
else if(condition3)
Action3
------------
------------
else
Last Action

Ans.4) if else is a bi-directional branching statement whereas switch case is a multiple branching
statement. Operators are used to check condition in if else whereas no operator is used to check
condition in switch case. float and double data type constants/variables can be checked in if else but not
in switch case.

Ans.5) A switch case is a multiple branching statement. It is used instead of writing multiple if else if
statements. It is used in menu driven programming.

Ans.6) A default statement is just like the else of if statement. The default statement executes when
none of the case value is matched with the switch variable. Use of default is optional in switch block.

Ans.7) In switch case, when any case value is matched with the switch variable, then statements in that
case block are executed and all other subsequent case blocks also get executed. This is called fall
through. To prevent fall through to happen, break keyword is used. The break keyword is a jump
statement. It terminates the switch block and takes the control out of it.

Ans.8) In switch case, when any case value is matched with the switch variable, then statements in that
case block are executed and all other subsequent case blocks also get executed. This is called fall
through.

Ans.9) A statement that contains one or more statements within its block is called a compound
statement. In the following example, if statement is a compound statement.
if(condition)
{
Statement1;
Statement2;
}

Ans.10) The if else if statement is used when more than two actions are to be taken. It checks one
condition and it is true then one action is taken otherwise another condition is checked and if that is
true then second action is taken otherwise next conditions are checked one by one and depending on
the result of those conditions, any one action is taken.
if(condition1)
Action1
else if(condition2)
Action2
else if(condition3)
Action3
------------
------------
else
Last Action
Ans.11) System.exit(0) will terminate the execution of a program in the middle of its execution. The
remaining statements in the program after System.exit(0) statement will not be executed.

Ans.12) if else is a bi-directional branching statement whereas switch case is a multiple branching
statement. Operators are used to check condition in if else whereas no operator is used to check
condition in switch case. float and double data type constants/variables can be checked in if else but not
in switch case.

Q.3) Predict the output of the followings.


Ans.1) 50
0
Ans.2) (i) x = 2, y = 2 (ii) x = 1, y = 1

Ans.3) 5.5

Ans.4)
(i) Object Oriented
Robust and Secure
(ii) Wrong Input
(iii) Platform Independent

Q.4) Correct the errors in the following programs.


Ans.1) System.out.println(sum +” “ + diff);

Ans.2) r = (int) Math.sqrt(n);


if(n = = r*r)

Ans.3) c = a*a + b * b;
d = (a +b) * (a + b);
int p = c / d;

Ans.4) k = Math.pow(p,2);
r = Math.sqrt(n);
Q.5) Unsolved Java programs.

Ans.1)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a, b, c;
System.out.println(“Enter three angles”);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
if( a+b+c == 180 && a > 0 && b > 0 && c > 0)
{
if(a<90 && b<90 && c<90)
System.out.println(“Acute angled triangle”);
else if(a==90 || b==90 || c==90)
System.out.println(“Right angled triangle”);
else
System.out.println(“Obtuse angled triangle”);
}
else
System.out.println(“A Triangle construction is not possible”);
}
}

Ans.2)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double cp, sp;
System.out.println(“Enter the cost price and sale price”);
cp = sc.nextDouble();
sp = sc.nextDouble();
if( sp > cp)
{
System.out.println(“Profit = “ + (sp – cp));
System.out.println(“Profit % = “ + (sp – cp)/cp * 100);
}
else if(cp > sp)
{
System.out.println(“Loss = “ + (cp – sp));
System.out.println(“Loss % = “ + (cp – sp)/cp * 100);
}
else
System.out.println(“Neither profit nor loss”);
}
}

Ans.3)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a, b, c;
System.out.println(“Enter three numbers”);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
if( a != b && a != c && b != c)
{
System.out.println(“Greatest Number = ” + Math.max(a, Math.max(b,c)));
}
else
System.out.println(“Numbers are equal”);
}
}
Ans.4)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a;
System.out.println(“Enter a number”);
a = sc.nextInt();
if( a % 3 = = 0 && a % 5 == 0))
System.out.println(“The number is divisible by 3 as well as by 5”);
else if(a % 3 == 0)
System.out.println(“The number is divisible by 3 and not by 5”);
else if(a % 5 == 0)
System.out.println(“The number is divisible by 5 and not by 3”);
else
System.out.println(“The number is neither divisible by 3 nor by 5”);

}
}

Ans.6)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int yr;
System.out.println(“Enter a year”);
yr = sc.nextInt();
if( yr % 100 == 0)
if ( yr % 400 == 0)
System.out.println(“It is both century year and leap year”);
else
System.out.println(“It is a century year”);
else if( yr % 4 == 0)
System.out.println(“It is a leap year”);
else
System.out.println(“It is a normal year”);

}
}

Ans.6)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a, b, c, d;
System.out.println(“Enter two unequal numbers”);
a = sc.nextInt();
b = sc.nextInt();
if ( a == b)
System.out.println(“Numbers are equal. Please enter two unequal numbers.”);
else if( a < 0 || b < 0)
System.out.println(“Square root of negative numbers cannot be determined”);
else
{
c = (int)Math.sqrt(a);
d = (int)Math.sqrt(b);
if(a == c *c && b == d *d)
System.out.println(“Both are perfect square numbers”);
else if(a==c*c)
System.out.println(a+“ is a perfect square number”);
else if(b==d*d)
System.out.println(b+“ is a perfect square number”);
else
System.out.println(“None of these are perfect square numbers”);
}
}
}
Ans.7)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a, b, c, d, hi, low, mid;
System.out.println(“Enter three unequal numbers”);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
if ( a != b && b != c && c != a )
{
hi = Math.max(a, Math.max(b, c));
low = Math.min(a, Math.min(b, c));
mid = (a + b + c) – (hi + low);
System.out.println(“Second smallest number = “ + mid);
}
else
{
System.out.println(“Numbers are not unequal”);
}
}
}

Ans.8)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a, b, c, d, hi, low;
System.out.println(“Enter three unequal numbers”);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
if ( a !=b && b !=c && c != a )
{
hi = Math.max(a, Math.max(b, c));
low = Math.min(a, Math.min(b, c));
System.out.println(“greatest = “ + hi + “ smallest = “ + low);
}
else
{
System.out.println(“Numbers are not unequal”);
}
}
}

Ans.9)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double km, amt=0;
System.out.println(“Enter the distance covered in kilometer”);
km = sc.nexDouble();
if( km < = 5)
amt = 100;
else if( km <= 15)
amt = 100 + (km – 5) * 10;
else if( km <= 25)
amt = 100 + 100 + (km – 15) * 8;
else
amt = 100 + 100 + 80 + (km – 25) * 5;
System.out.println(“ Taxi No. 9211”);
System.out.println(“Distance covered = “ + km);
System.out.println(“Amount = “ + amt);
}
}
Ans.10)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double cost, dis = 0, net =0;
String gift;
System.out.println(“Enter the total cost of purchase”);
cost = sc.nextDouble();
if( cost < = 2000)
{
dis = 5/100.0 * cost;
gift = “Calculator”;
}
else if( cost <= 5000)
(
dis = 10/100.0 * cost;
gift = “School Bag”;
}
else if( cost < = 10000)
{
dis = 15/100.0 * cost;
gift = “Wall Clock”;
}
else
{
dis = 20/100.0 * cost;
gift = “Wrist Watch”;
}
net = cost – dis;
System.out.println(“ Net amount to be paid = ” + net);
System.out.println(“Gift = “ +gift);
}
}
Ans.11)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int ag; String nm;
double ti, tax=0;
System.out.println(“Enter name, age and taxable income”);
nm = sc.nextLine();
ag = sc.nextInt();
ti = sc.nexDouble();
if( ti < =250000)
tax = 0;
else if( ti <= 500000)
tax = (ti – 250000) * 0.10;
else if( ti <= 1000000)
tax = (ti – 500000) * 0.20 + 25000;
else
tax = (ti – 1000000) * 0.30 + 125000;
if(ag <= 60)
{
System.out.println(“Name = “ + nm);
System.out.println(“Tax Payable = “ + tax);
}
else
System.out.println(“Wrong category”);
}
}
Ans.12)
import java.util.*;
class A
{
public static void main(String args[])
{
System.out.println("Enter sum to be deposited and number of days to be deposited");
Scanner sc=new Scanner(System.in);
double amt=0;
double sum = sc.nextDouble();
int day = sc.nextInt();
if(day <= 180)
amt = sum * Math.pow(1+5.5/100,0.5);
else if( day <= 364)
amt = sum * Math.pow(1+7.5/100,1);
else if( day == 365)
amt = sum * Math.pow(1+9.0/100,1);
else
amt = sum * Math.pow(1+8.5/100,day/365);
System.out.println("Maturity Amount = "+amt);
}
}

Ans.13)
import java.util.*;
class A
{
public static void main(String args[])
{
System.out.println("Enter the name of policy holder”);
Scanner sc=new Scanner(System.in);
String nm=sc.nextLine();
System.out.println(“Enter the sum assured”);
double sum = sc.nextDouble();
System.out.println(“Enter the first premium amount”);
double prem = sc.nextDouble();
double dis=0, comm=0;
if(sum <= 100000)
{
dis = 0.05 * prem;
comm = 0.02 * sum;
}
else if(sum <= 200000)
{
dis = 0.08 * prem;
comm = 0.03 * sum;
}
else if(sum <= 500000)
{
dis = 0.10 * prem;
comm = 0.05 * sum;
}
else
{
dis = 0.15 * prem;
comm = 0.75 * sum;
}
System.out.println("Name of the policy holder = "+nm);
System.out.println("Sum assured = "+sum);
System.out.println("Premium = "+prem);
System.out.println("Discount on first premium = "+dis);
System.out.println("Commission = "+comm);
}
}

Ans.14)
import java.util.*;
class A
{
public static void main(String args[])
{
System.out.println("Enter the name of the employee”);
Scanner sc=new Scanner(System.in);
String nm=sc.nextLine();
System.out.println(“Enter the basic salary”);
double bs = sc.nextDouble();
double da=0, sa=0, gross=0;
if(bs <= 100000)
{
da = 0.10 * bs;
sa = 0.05 * bs;
}
else if(bs <= 200000)
{
da = 0.12 * bs;
sa = 0.08 * bs;
}
else if(bs <= 300000)
{
da = 0.15 * bs;
sa = 0.10 * bs;
}
else
{
da = 0.20 * bs;
sa = 0.12 * bs;
}
gross = bs + da + sa;
System.out.println("Name \t Basic \t DA \t Spl. Allowance \t Gross Salary);
System.out.println(nm + “\t” + bs + “\t” + da + “\t” + sa + “\t” + gross);
}
}

Ans.15)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double c, f;
System.out.println(“Enter 1 to convert Fahrenheit to Celsius”);
System.out.println(“Enter 2 to convert Celsius to Fahrenheit”);
int ch=sc.nexInt();
switch(ch)
{
case 1:
System.out.println(“Enter Temperature in Fahrenheit”);
f=sc.nextDouble();
c=(f – 32) * 5/9.0;
System.out.println(“Temperature in Celsius = ” + c);
break;
case 2:
System.out.println(“Enter Temperature in Celsius”);
c=sc.nextDouble();
f=c * 9/5.0 + 32;
System.out.println(“Temperature in Fahrenheit = ” + f);
break;
default:
System.out.println(“Wrong choice”);
}
}
}

Ans.16)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double l, b, h, r, v;
System.out.println(“Enter 1 for volume of cuboid”);
System.out.println(“Enter 2 for volume of cylinder”);
System.out.println(“Enter 3 for volume of cone”);
int ch=sc.nexInt();
switch(ch)
{
case 1:
System.out.println(“Enter length, breadth and height of cuboid”);
l=sc.nextDouble();
b=sc.nextDouble();
h=sc.nextDouble();
v=l*b*h;
System.out.println(“Volume of cuboid = ” + v);
break;
case 2:
System.out.println(“Enter radius and height of cylinder”);
r=sc.nextDouble();
h=sc.nextDouble();
v=22/7.0 * Math.pow(r,2) * h;
System.out.println(“Volume of cylinder = ” + v);
break;
case 3:
System.out.println(“Enter radius and height of cone”);
r=sc.nextDouble();
h=sc.nextDouble();
v=1/3.0 * h * 22/7.0 * Math.pow(r,2);
System.out.println(“Volume of cone = ” + v);
break;
default:
System.out.println(“Wrong choice”);
}
}
}

Ans.18)
import Java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double r1, r2, R1, R2;
System.out.println(“Enter two resistances”);
r1=sc.nextDouble();
r2=sc.nextDouble();
R1=r1+r2;
R2=(r1*r2)/(r1+r2);
System.out.println(“The equivalent resistance of series = “ + R1);
System.out.println(“The equivalent resistance of parallel = “ + R2);
}
}

Ans.19)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double P, T, R, SI=0, CI=0;
System.out.println(“Enter Principal, Time and Rate”);
P=sc.nextDouble();
T=sc.nextDouble();
R=sc.nextDouble();
System.out.println(“Enter ‘S’ for Simple Interest and ‘C’ for Compound Interest”);
char ch=sc.nextt().charAt(0);
switch(ch)
{
case ‘S’: System.out.println(“Simple Interest = “ + (P*T*R)/100);
break;
case ‘C’:
System.out.println(“Compound Interest = “ + (P*(Math.pow(1+R/100,T) – P) );
break;
default: System.out.println(“Wrong Choice”);
}
}
}

Ans.20)
import java.util.*;
class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double dis=0, net=0;
System.out.println(“Enter Name of the Customer”);
String nm=sc.nextLine();
System.out.println(“Enter the Amount of Purchase”)
double pa=sc.nextDouble();
System.out.println(“Enter ‘L’ for Laptop and ‘D’ for Desktop Computer”);
char pur_type=sc.nextt().charAt(0);
if(pur_type==’L’)
{
if(pa<=25000)
dis=0;
else if(pa<=50000)
dis=0.05*pa;
else if(pa<=100000)
dis=0.75*pa;
else
dis=0.10*pa;
net=pa – dis;
System.out.println(“Name = “ + nm);
System.out.println(“Net Amount = “ + net);
}
else if(pur_type = =’D’)
{
if(pa<=25000)
dis=0.05*pa;
else if(pa<=50000)
dis=0.75*pa;
else if(pa<=100000)
dis=0.10*pa;
else
dis=0.15*pa;
System.out.println(“Name = “ + nm);
System.out.println(“Net Amount = “ + net);
}
else
System.out.println(“Wrong Choice”);
}
}

You might also like