Comp - Project Book
Comp - Project Book
import java.util.*;
public class CI
{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter sum of money: ");
double p = sc.nextDouble();
double inter = p * 5 * 1 / 100.0;
System.out.println("Interest for the first year = " + inter);
p += inter;
inter = p * 5 * 1 / 100.0;
System.out.println("Interest for the second year = " + inter);
p += inter;
inter = p * 5 * 1 / 100.0;
System.out.println("Interest for the third year = " + inter);
}
}
Question 7
import java.util.*;
import java.util.*;
import java.util.*;
Question 1
import java.util.*;
import java.util.*;
import java.util.*;
import java.util.*;
import java.util.Scanner;
import java.util.*;
/*
* Extra Question - Write a Program to display Grades of student as follows:
If marks >=90 then A+
If marks >=80 then A
If marks >=70 then B+
If marks >=65 then B
If marks >=60 then C
If marks >=50 then D
*/
public class mark
{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Marks");
int m = sc.nextInt();
if(m>0)
{
if(m>=90 && m<=100) System.out.println("Marks = A+");
else if(m>=80 && m<=89) System.out.println("Marks = A");
else if(m>=70 && m<=79) System.out.println("Marks = B+");
else if(m>=65 && m<=69) System.out.println("Marks = B");
else if(m>=60 && m<=64) System.out.println("Marks = C");
else System.out.println("Marks = D");
}
}
}
Question 1 pg 178
import java.util.*;
}
}
Question 5
import java.util.*;
import java.util.*;
int c = 0;
if (d <= 5)
c = 100;
else if (d <= 15)
c = 100 + (d - 5) * 10;
else if (d <= 25)
c = 100 + 100 + (d - 15) * 8;
else
c = 100 + 100 + 80 + (d - 25) * 5;
}
}
Question 13
import java.util.*;
public class lic
{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Name: ");
String name = sc.nextLine();
System.out.println("Enter Sum Assured: ");
double sum = sc.nextDouble();
System.out.println("Enter First Premium: ");
double pre = sc.nextDouble();
double disc = 0.0, com = 0.0;
if(sum <= 100000){
disc = pre * 5.0 / 100.0;
com = sum * 2.0 / 100.0;
}
else if(sum <= 200000){
disc = pre * 8.0 / 100.0;
com = sum * 3.0 / 100.0;
}
else if(sum <= 500000){
disc = pre * 10.0 / 100.0;
com = sum * 5.0 / 100.0;
}
else{
disc = pre * 15.0 / 100.0;
com = sum * 7.5 / 100.0;
}
System.out.println("Name of the policy holder: " + name);
System.out.println("Sum assured: " + sum);
System.out.println("Premium: " + pre);
System.out.println("Discount on the first premium: " + disc);
System.out.println("Commission of the agent: " + com);
}
}
Question 16
import java.util.*;
public class volmenu
{
public static void main(String args[]) {
Scanner sc= new Scanner(System.in);
System.out.println("1. Volume of cuboid");
System.out.println("2. Volume of cylinder");
System.out.println("3. Volume of cone");
System.out.println("Enter your choice: ");
int ch = sc.nextInt();
switch(ch) {
case 1:
System.out.print("Enter length of cuboid: ");
double l = sc.nextDouble();
System.out.print("Enter breadth of cuboid: ");
double b = sc.nextDouble();
System.out.print("Enter height of cuboid: ");
double h = sc.nextDouble();
double vol = l * b * h;
System.out.println("Volume of cuboid = " + vol);
break;
case 2:
System.out.println("Enter radius of cylinder: ");
double rCy = sc.nextDouble();
System.out.println("Enter height of cylinder: ");
double hCy = sc.nextDouble();
double vCy = (22 / 7.0) * Math.pow(rCy, 2) * hCy;
System.out.println("Volume of cylinder = " + vCy);
break;
case 3:
System.out.print("Enter radius of cone: ");
double rCo = sc.nextDouble();
System.out.println("Enter height of cone: ");
double hCo = sc.nextDouble();
double vCo = (1 / 3.0) * (22 / 7.0) * Math.pow(rCo, 2) * hCo;
System.out.println("Volume of cone = " + vCo);
break;
default:
System.out.println("Wrong choice! Please select from 1 or 2 or 3.");
}
}
}
Question 19
import java.util.*;
switch (t) {
case 'S':
inter = p * r * ti / 100;
break;
case 'C':
inter = p * (Math.pow((1 + (r / 100)), ti) - 1);
break;
default:
isT = false;
System.out.println("Incorrect Interest type");
break;
}
if (isT) {
double amt = p + inter;
System.out.println("Sum = " + p);
System.out.println("Interest = " + inter);
System.out.println("Sum + Interest = " + amt);
}
}
}
Page 230 question 5
import java.util.*;
public class psqr
{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter m: ");
int m = sc.nextInt();
System.out.println("Enter n: ");
int n = sc.nextInt();
if (m < n && m > 0 && n > 0) {
for (int i = m; i <= n; i++) {
System.out.println("Number = " + i);
double sroot = Math.sqrt(i);
if (sroot == Math.floor(sroot))
System.out.println(i + " is a perfect square");
}
}
else System.out.println("Invalid input");
}
}
Question 6
import java.util.*;
public class buzz
{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter p: ");
int p = sc.nextInt();
System.out.println("Enter q: ");
int q = sc.nextInt();
if (p < q) {
System.out.println("Buzz Numbers between " + p + " and " + q);
for (int i = p; i <= q; i++) {
if (i % 10 == 7 || i % 7 == 0)
System.out.println(i);
}
}
else System.out.println("p should be less than q");
}
}
Question 10
import java.util.*;
public class rev
{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number: ");
int org = sc.nextInt();
int copy = org;
int rev = 0;
while(copy != 0) {
int dig = copy % 10;
copy /= 10;
rev = rev * 10 + dig;
}
int diff = rev - org;
System.out.println("Reversed Number = " + rev);
System.out.println("Absolute Difference = " + Math.abs(diff));
}
}
Question 11
import java.util.*;
public class gcd
{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter first number: ");
int a = sc.nextInt();
System.out.println("Enter second number: ");
int b = sc.nextInt();
while (b != 0) {
int t = b;
b = a % b;
a = t;
}
System.out.println("GCD=" + a);
}
}
Pg 265
Question 14 a
import java.util.*;
public class series1
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter n: ");
int n = sc.nextInt();
double s = 0.0;
for (int i = 1; i <= n; i++)
{
double f = 1;
for (int j = 1; j <= i; j++) f *= j;
s += (1.0 / f);
}
System.out.println("Series=" + s);
}
}
Part d
import java.util.*;
public class series2
{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter n");
int n = sc.nextInt();
double s = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) s += j;
}
System.out.println("Series=" + s);
}
}
15)c and e