0% found this document useful (0 votes)
17 views29 pages

Project

Uploaded by

soumalayapc
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)
17 views29 pages

Project

Uploaded by

soumalayapc
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

Project – 1

Name: Soumalaya Pal


Class: IX
Section: A
Roll no.: 08/2011
Serial no.:29
Subject: Computer Application

1./*Input a number and check whether the number is divisible


by 3 as well as 5*/
import java.util.*; //Import java package
class Prog //Declare the class
{
public static void main(String args[]) //main method
{
Scanner in=new Scanner (System.in);
System.out.print(“Enter the number”);
int num=in.nextInt(); //Declare the variable and Input the
value
if (num % 3==0 && num % 5==0)
System.out.print(“Divisible by 3 and 5”);
else if (num % 3==0)
System.out.print(“Divisible by 3 but not by 5”):
else if (num % 5==0)
System.out.print(“Divisible by 5 but not by 3’);
else
System.out.print(“Neither divisible by 3 nor by 5”);
} //end of main method
} //end of class

Variable listing
Variable Datatype Input Output Function
num int To input _____ To check
variable that if a
number is
divisible
by 3 as
well as 5.

2./*Input year and check whether it is a leap year, a century


leap year or a century year*/
import java.util.*; //Import java package
class Prog //Declare the class
{
public static void main(String args[]) //main method
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the year to check: ");
int yr = in.nextInt();//Declare the variable and Input the value
if (yr % 4 == 0 && yr % 100 != 0) System.out.println("It is a
Leap Year");
else if (yr % 400 == 0)
System.out.println("It is a Century Leap Year");
else if (yr % 100 == 0)
System.out.println("It is a Century Year but not a Leap
Year");
else
System.out.println("It is neither a Century Year nor a Leap
Year");
}//end of main method
}//end of class

Variable listing
Variable Data Type Input Output Function
yr int To input ______ To check
vaiable that a year
is a leap
year or a
century
leap year
or century
year

3./* Input two unequal positive numbers and check whether


they are perfect square or not*/
import java.util.*; //Import java package
class prog //Declare the class
{
public static void main(String args[])//Main method
{
Scanner in = new Scanner(System.in);
System.out.print("Enter first number: ");
int a = in.nextInt(); //Declare the variable a and input the
value
System.out.print("Enter second number: ");
int b = in.nextInt();//Declare the variable b and input the
value

if (a < 0 || b < 0) {
System.out.println("Square root of a negative number
can't be determined");
}
else {
double sqrtA = Math.sqrt(a);
double sqrtB = Math.sqrt(b);
double isAPerfectSq = sqrtA - Math.floor(sqrtA);
double isBPerfectSq = sqrtB - Math.floor(sqrtB);

if (isAPerfectSq == 0 && isBPerfectSq == 0) {


System.out.println("They are perfect square
numbers.");
}
else if (isAPerfectSq == 0) {
System.out.println(a + " is a perfect square
number.");
System.out.println(b + " is not a perfect square
number.");
}
else if (isBPerfectSq == 0) {
System.out.println(a + " is not a perfect square
number.");
System.out.println(b + " is a perfect square
number.");
}
else {
System.out.println("Both are not perfect square
numbers.");
}
}
}
}

Variable listing
Variable Data Type Input Output Function
a Int To input To print if To check
variable the that if the
number is number is
perfect a perfect
square square or
not
b Int To input To print if To check
variable the that if the
number is number is
a perfect perfect
square square or
not
4. /*to input the total cost and display the amount to be paid
by the customer*/
import java.util.*; //Import java packages

public class prog_3 //Declare the class


{
public static void main(String args[]) //Main method
{
Scanner in = new Scanner(System.in);
System.out.print("Enter total cost: ");
double cost = in.nextDouble(); //Declare the variable and
double the value
String gift;
double amt;

if (cost <= 2000.0) {


amt = cost - (cost * 5 / 100);
gift = "Calculator";
}
else if (cost <= 5000.0) {
amt = cost - (cost * 10 / 100);
gift = "School Bag";
}
else if (cost <= 10000.0) {
amt = cost - (cost * 15 / 100);
gift = "Wall Clock";
}
else {
amt = cost - (cost * 20 / 100);
gift = "Wrist Watch";
}
System.out.println("Amount to be paid: " + amt);
System.out.println("Gift: " + gift);

}
}
Variable listing
Variable Data Type Input Output Function
cost double To input To input
the total ________ the total
cost price
gift string To print To find
the gift out the gift
amt double To print To get the
the final price
amount to to be paid
be paid
5./*to input the name, age and taxable income and display the
payable income tax*/
import java.util.*; //import java packages

class income_tax //declare the class


{
public static void main(String args[]) //main method
{
Scanner in = new Scanner(System.in);
System.out.print("Enter Name: ");
String name = in.nextLine();
System.out.print("Enter age: ");
int age = in.nextInt();
System.out.print("Enter taxable income: ");
double ti = in.nextDouble();
double tax = 0.0;

if (age > 60) {


System.out.print("Wrong Category");
}
else {
if (ti <= 250000)
tax = 0;
else if (ti <= 500000)
tax = (ti - 160000) * 10 / 100;
else if (ti <= 1000000)
tax = 34000 + ((ti - 500000) * 20 / 100);
else
tax = 94000 + ((ti - 1000000) * 30 / 100);
}

System.out.println("Name: " + name);


System.out.println("Tax Payable: " + tax);
}
}
Variable Listing
6.//to input the amount for term deposit scheme in bank and
display the maturity amount
import java.util.*; //Import java package

class Deposit //Declare the class


{
public static void main(String args[]) //Main method
{
Scanner in = new Scanner(System.in);
System.out.print("Enter sum of money: ");
double sum = in.nextDouble();
System.out.print("Enter number of days: ");
int days = in.nextInt();
double interest = 0.0;

if (days <= 180)


interest = sum * 5.5 / 100.0;
else if (days <= 364)
interest = sum * 7.5 / 100.0;
else if (days == 365)
interest = sum * 9.0 / 100.0;
else
interest = sum * 8.5 / 100.0;
double amt = sum + interest;
System.out.print("Maturity Amount = " + amt);
}
}

Variable Listing
7.//to input the sum assured of the policy holder and display
the name, sum assured and first premium
import java.util.*; // Import java packages
class prog_4 // Declare the class
{
public static void main(String args[]) //main method
{
Scanner in = new Scanner(System.in);
System.out.print("Enter Name: ");
String name = in.nextLine();
System.out.print("Enter Sum Assured: ");
double sum = in.nextDouble();
System.out.print("Enter First Premium: ");
double pre = in.nextDouble();
double disc = 0.0, comm = 0.0;

if(sum <= 100000){


disc = pre * 5.0 / 100.0;
comm = sum * 2.0 / 100.0;
}
else if(sum <= 200000){
disc = pre * 8.0 / 100.0;
comm = sum * 3.0 / 100.0;
}
else if(sum <= 500000){
disc = pre * 10.0 / 100.0;
comm = sum * 5.0 / 100.0;
}
else{
disc = pre * 15.0 / 100.0;
comm = 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: " +
comm);

}
}

Variable listing
8.//to accept the name and basic salary and display gross
salary
import java.util.*; // Import java package

class salary //Declare the class


{
public static void main(String args[]) // Main method
{
Scanner in = new Scanner(System.in);
System.out.print("Enter name: ");
String name = in.nextLine();
System.out.print("Enter basic salary: ");
double bs = in.nextDouble();
double da = 0.0, sa = 0.0;
if (bs <= 10000){
da = bs * 10.0 / 100.0;
sa = bs * 5.0 / 100.0;
}
else if (bs <= 20000){
da = bs * 12.0 / 100.0;
sa = bs * 8.0 / 100.0;
}
else if (bs <= 30000){
da = bs * 15.0 / 100.0;
sa = bs * 10.0 / 100.0;
}
else{
da = bs * 20.0 / 100.0;
sa = bs * 12.0 / 100.0;
}
double gs = bs + da + sa;
System.out.println("Name\tBasic\tDA\tSpl. Allowance\
tGross Salary");
System.out.println(name + "\t" + bs + "\t" + da + "\t" + sa
+ "\t" + gs);
}
}

Variable listing
9.//to calculate and display the volume of solids
import java.util.*; // Import java packages

class volume // Declare the class


{
public static void main(String args[]) // Main method
{
Scanner in = 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.print("Enter your choice: ");
int choice = in.nextInt();

switch(choice)
{
case 1:
System.out.print("Enter length of cuboid: ");
double l = in.nextDouble();
System.out.print("Enter breadth of cuboid: ");
double b = in.nextDouble();
System.out.print("Enter height of cuboid: ");
double h = in.nextDouble();
double vol = l * b * h;
System.out.println("Volume of cuboid = " + vol);
break;

case 2:
System.out.print("Enter radius of cylinder: ");
double rCylinder = in.nextDouble();
System.out.print("Enter height of cylinder: ");
double hCylinder = in.nextDouble();
double vCylinder = (22 / 7.0) *
Math.pow(rCylinder, 2) * hCylinder;
System.out.println("Volume of cylinder = " +
vCylinder);
break;

case 3:
System.out.print("Enter radius of cone: ");
double rCone = in.nextDouble();
System.out.print("Enter height of cone: ");
double hCone = in.nextDouble();
double vCone = (1 / 3.0) * (22 / 7.0) *
Math.pow(rCone, 2) * hCone;
System.out.println("Volume of cone = " + vCone);
break;
default:
System.out.println("Wrong choice! Please select
from 1 or 2 or 3.");
}
}
}
Variable listing
8.//to input and display the amount paid by a customer for
laptop or destop
class prog_5 //Declare the class
{
public static void main(String args[]) //main method
{
Scanner in = new Scanner(System.in);
System.out.print("Enter Name: ");
String name = in.nextLine();
System.out.print("Enter Amount of Purchase: ");
double amt = in.nextDouble();
System.out.println("Enter Type of Purchase");
System.out.print("'L'- Laptop or 'D'- Desktop: ");
char type = in.next().charAt(0);
type = Character.toUpperCase(type);
double disc = 0.0;

if (amt <= 25000)


disc = type == 'L' ? 0.0 : 5.0;
else if (amt <= 50000)
disc = type == 'L' ? 5.0 : 7.0;
else if (amt <= 100000)
disc = type == 'L' ? 7.5 : 10.0;
else
disc = type == 'L' ? 10.0 : 15.0;

double netAmt = amt - (disc * amt / 100);

System.out.println("Name: " + name);


System.out.println("Net Amount: " + netAmt);
}
}
Variable listing

You might also like