Computer Project
Computer Project
Acknowledgement
I would like to express special thanks to my
Computer teacher who gave me this golden
opportunity to do this wonderful project. Her
guidance helped me to wonderfully do this project.
Her major contributions towards the completion of
the project. I would also like to thank my parents to
give me their guidance and suggestions for the
project.
Q. 1 A computer store announced stock clearing sale. They were offering both
a discount and a gift. Write a program in Java to input the purchase amount
and print the amount payable. Also print the gift that should be given to the
customer:
import java.util.*;
public class DiscounGift
{//Class begins
public static void main (String args [])
{//Main begins
Scanner sc=new Scanner (System.in);
System.out.println("Computer Store");
System.out.println();
System.out.println("Stock Clearing Sale");
System.out.println();
System.out.println("Enter purchase amount=");//Asking user to enter purchase
amount
int pa=sc.nextInt();
double total;//Declaring variable
if (pa<12000&pa>=5000)//If purchase is greater than 12000 and less than 15000
{
total=pa-(11/100.0*pa);
System.out.println("Gift-digital table clock");
else if(pa<15000&pa>=12000)//If purchase is greater than or equal to 15000 and
less than 1000
{
total=pa-(16/100.0*pa);
System.out.println("Gift-Wall clock");
}
else if (pa<20000&pa>=15000)
{
total=pa-(20/100.0*pa);
System.out.println ("Wrist watch");
}
else if (pa>=20000)
{
total=pa-(25/100.0*pa);
System.out.println ("Music System");
}
else
{
total=pa-(5/100.0*pa);
System.out.println("Pen set");
}
System.out.println("Discounted price="+total);
}//Main close
}//Class close
Q.2 A paper manufacturing factory revised the salary scale of its employees
depending on the number of years of service. Write a program in java to input
the number of years of service and the current salary. Calculate and display
the revised amount an employee will get as salary, on the given following rate
of increment:
Years of service (Y) Rate of increment (R)
Y<5 5% of salary (S)
Y <10&Y>=5 7% of salary (S)
Y<15&Y>=10 10% of salary (S)
Otherwise 12% of salary (S)
import java.util.*;
public class Salary
{
public static void main()
{
Scanner sc=new Scanner(System.in);//Declaring scanner class;
System.out.println("Paper Manufacturing Factory");
System.out.println();
System.out.println("Revised Amount of Salary");
System.out.println();
System.out.println("Enter present Salary=");
int s=sc.nextInt();
System.out.println("Enter years of service");
int service=sc.nextInt();
double total;
if(service<5)
{
total=s+(5/100.0*s);
System.out.println("Congrats!!! You have got a 5% increment");
}
else if(service<10&&service>=5)
{
total=s+(7/100.0*s);
System.out.println("Congrats!!! You have got a 7% increment");
}
else if(service<15&&service>=10)
{
total=s+(10/100.0*s);
System.out.println("Congrats!!! You have got a 10% increment");
}
else//For more than 15 years of service;
{
total=s+(12/100.0*s);
System.out.println("Congrats!!! You have got a 12% increment");
}
System.out.println("Incremented Salary=Rs"+total);
}
}
Q.3 Write a program in Java to print the sum of the series:
10 + 11 + 9 + 12 + 8 + 13 + 7 +…up to n terms
import java.util.*;
public class Series
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of terms");
int n=sc.nextInt();
int sum=10;
int i=11;
int c=0;
do
{
sum=sum+i+(20-i);
c=c+3;
i++;
}
while(c<=n);
System.out.println("Sum="+sum);
}
}
Q.4 Write a program in Java to print the following pattern:
1
$ #
1 $ 1
# 1 1 1
$ 1 # 1 $
import java.util.*;
public class Pattern
{//Class begins
public static void main (String args[])
{//Main begins
Scanner sc= new Scanner (System.in);//Declaring scanner class
int i,k,j,p=0,l=0,c=0;//Declaring variables
{
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
p=p+1;
c=0;
for(k=1;k<=p;k++)
{
if(p%k==0)
c++;//counter increases
}
if(p==15)//To check if p is equal to 15
System.out.print("$");
else if(c==2)//To check if counter is equal to 2
{
l++;
if(l%2==0)//To check if l % 2 is equal to 0
{
System.out.print("#"); //To print #
}
else
System.out.print("$"); //To print $
}
else
System.out.print("1");//To print 1
}
System.out.println();//To print the pattern
}
}
}//Main close
}// Class close
Q.6 Write a program in Java to print the following pattern:
543212345
5432345
54345
545
5
import java.util.*;
public class Pattern2
{//Class begins
public static void main (String args[])
{//Main begins
Scanner sc = new Scanner (System.in);//Declaring scanner class
int i,j,k;// Declaring variables
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
System.out.print(j);// To print j
}
for(k=i+1;k<=5;k++)
{
System.out.print(k);// To print k
}
System.out.println();// To print the pattern
}
}// Main close
}// Class close
12345
2345
345
45
5
import java.util.*;
public class Pattern3
{
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
for(int i = 1;i<=5;i++)
{
for(int j = 1;j<i;j++)
{
System.out.print(" ");
}
for(int k=i;k<=5;k++)
{
System.out.print(k);
}
System.out.println();
}
}
}
Q.9 Write a program in Java to accept a number from the user and
check whether it is Disarium Number or not.
import java.util.*;
public class DisariumNumber
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a Number");
int n=sc.nextInt();
String s = Integer.toString(n);
int l = s.length();
int a,num;
double sum=0;
num=n;
while(n>0)
{
a=n%10;
sum=sum+Math.pow(a,l);
l--;
n=n/10;
}
if(num==sum)
{
System.out.println("The number is a Disarium Number");
}
else
System.out.println("The number is not a Disarium Number");
}
}
Q.10 Write a program in Java to accept a number from the user and check
whether it is Pronic Number or Heteromecic Number or not.
Pronic Number : A pronic number, oblong number, rectangular number
or heteromecic number, is a number which is the product of two consecutive
integers, that is, n (n + 1).
import java.util.*;
public class question10
{//Class begins
public static void main (String args[])
{//Main begins
Scanner sc= new Scanner (System.in);//Declaring scanner class
System.out.println("Enter a number");//Asking the user to enter a number
int n=sc.nextInt();//Accepting the the number
int i=1;//Assigning value to i
do
{
if(i*(i+1)==n)
{
System.out.println("The number is a pronic number");
System.exit(0);
}
i++;
}
while(i<=n);
System.out.println("The number is not a pronic number");
}//Main close
}//Class close