Java project class IX Maria Day School

Q1. Write a program to find net pay where basic  salary taken as input.
da= 25% of basic salary
ta= 2% basic salary
pf= 15% basic salary
gross pay= basic salary+da+ta
net pay=gross pay – pf
Solution:
import java.util.*;
//Start of clas Employee
public class Employee
{
    public static void main(String args[])
    {
        //Local variables
        double bs,da,ta,pf,gp,np;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter Basic salary:");
        bs=sc.nextDouble();
        da=bs*25.0/100.0;
        ta=bs*2.0/100.0;
        pf=bs*15.0/100.0;
        gp=bs+da+ta;
        np=gp-pf;
        System.out.println("Gross payment:"+gp);
        System.out.println("Net Payment :"+np);
    }//end of main
}//end of class

Q2. Write a program to input radius and find volume and surface area of a Sphere.
[ sa=4  π r2      v=4/3 π r3 ]
Solution
import java.util.*;
//Start of clas Sphere
public class Sphere
{
    public static void main(String args[])
    {
        //Local variables
        double v,sa,r,pi=314;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter Radius of Sphere:");
        r=sc.nextDouble();
        sa=4*pi*r*r;
        v=(double)4/3*pi*r*r*r;
        System.out.println("Surface area="+sa);
        System.out.println("Volume  ="+v);
    }
}end of the class







Q3. Write a program to accept a year and check whether the year is Leap year or not. If the year in century then it is divisible by 400. If it is non-century year then it is divisible by 4 but not 100.
Solution:
import java.util.*;
//Start of clas Leap Year
public class LeapYear
{
    public static void main(String args[])
    {
        //Local variables
        int year;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter year :");
        year=sc.nextInt();
        if ((year % 4 == 0) && year % 100 != 0)
        {
            System.out.println(year + " is a leap year.");
        }
        else if ((year % 4 == 0) && (year % 100 == 0) && (year % 400 == 0))
        {
            System.out.println(year + " is a leap year.");
        }
        else
        {
            System.out.println(year + " is not a leap year.");
        }
    }

} end of the class

SHARE THIS
Previous Post
Next Post