.

Friday, 27 March 2015

Small shopping project in JAVA

import java.util.Scanner;
class Product
{
Scanner sc=new Scanner(System.in);
int ProductID;
String ProductName, ProductType;
float ProductPrice;

Product()
{
System.out.print("Enter the Product ID = ");
ProductID=sc.nextInt();
System.out.print("Enter the Product Name = ");
ProductName=sc.next();
System.out.print("Enter the Product Type = ");
ProductType=sc.next();
System.out.print("Enter the Product Price = ");
ProductPrice=sc.nextFloat();

}
void ViewAllProduct()
{
System.out.print("\n\nEnter the Product ID = "+ProductID);
System.out.print("\nEnter the Product Name = "+ProductName);
}

void ViewProductDetails(int ID)
{
if(ProductID==ID)
{

System.out.print("The Product ID = "+ProductID);
System.out.print("\nThe Product Name = "+ProductName);
System.out.print("\nThe Product Type = "+ProductType);
System.out.print("\nThe Product Price = "+ProductPrice);
}
}

}

class Shop extends Product
{
public static void main(String s[])
{
Scanner sc1=new Scanner(System.in);
Product ob[]=new Product[5];

for(int i=0;i<5;i++)
{
ob[i]=new Product();
}

System.out.print("\n\n Please Press an Option :\n1 to view all Product\n2 to see prouct details\n3 to EXIT\n\nEnter your choice = ");
int c=sc1.nextInt();

if(c==1)
{
for(int i=0;i<5;i++)
{
ob[i].ViewAllProduct();
}
}

if(c==2)
{
System.out.print("\n\nEnter the Product ID for details = ");
int x=sc1.nextInt();
for(int i=0;i<5;i++)
{
ob[i].ViewProductDetails(x);
}

}
if(c==3)
{
System.exit(0);
}
else
{
System.out.print("\n\nWrong Input");
}

}
}
Read more ...

Matrix addition program in JAVA

import java.util.Scanner;
class addm
{
 public static void main(String[] arg)
 {
  int i,j;
 int a[][]=new int[3][3];
 Scanner sc=new Scanner(System.in);
 for(i=0;i<3;i++)
 {
   for(j=0;j<3;j++)
 {
  a[i][j]=sc.nextInt();
 }
}
  int b[][]=new int[3][3];
 for(i=0;i<3;i++)
 {
   for(j=0;j<3;j++)
 {
  b[i][j]=sc.nextInt();
}
}
int c[][]=new int[3][3];
 for(i=0;i<3;i++)
 {
   for(j=0;j<3;j++)
 {
  c[i][j]=a[i][j]+b[i][j];
 System.out.println("Matrix Addition="+c[i][j]);
}
}
}
}
Read more ...

Program to find diagonal elements in matrix

import java.util.Scanner;
class diagonalm
{
 public static void main(String[] arg)
 {
  int i,j;
 int a[][]=new int[3][3];
 Scanner sc=new Scanner(System.in);
 for(i=0;i<3;i++)
 {
   for(j=0;j<3;j++)
 {
  a[i][j]=sc.nextInt();
 }
}
System.out.println("Left diagonal elements=0");
 for(int k=0;k<3;k++)
 {
   for(int l=0;l<3;l++)
 {
 if(k==l)
 {
 System.out.println(a[k][l]);
}
}
}
 System.out.println("Right diagonal elements=0");
 for(int m=0;m<3;m++)
 {
   for(int n=0;n<3;n++)
 {
  if(m+n==2)
 {
  System.out.println(a[m][n]);
 }
}
}
}
}


Read more ...

Download program of LOGIC GATE IN JAVA

AND GATE

package logicgate;
 public class and
{
 int z1;
 public int dooperation(int x1,int y1)
 {
  int z;
  z=x1*y1;
  z1=z;
 return(z1);
}
 

 }

 NOT GATE
package logicgate;

 public class not
 {

 public int dooperation(int x3)
 {
  int z3;
  {
   if(x3==0)
   z3=1;
   else
   z3=0;
   return(z3);
 }
 }
  }


OR GATE
package logicgate;

 public class or
{
 int z2;
 public int dooperation(int x2,int y2)
 {
 int z;
 z=x2+y2;
 z2=z;
  return(z2);
 }
 
 }

MAIN CLASS


import logicgate.and;
import logicgate.or;
import logicgate.not;

 class Main
{
 public static void main(String[] arg)
{
 and ob1=new and();
 or ob2=new or();
 not ob3=new not();
 ob1.dooperation(0,1);
 ob2.dooperation(0,0);
 ob3.dooperation(0);
}
}

Read more ...

Program to find pallindrome in JAVA

class Pallindrome
{
public static void main(String args[])
{
int num=131;
int r,temp,sum=0;
temp=num;
while(num!=0)
{
r=num%10;
num=num/10;
sum=sum*10+r;
}
if(sum==temp)
System.out.println("no. is pallindrome");
else
System.out.println("no. is not pallindrome");
}
}
Read more ...

Program to find electricity bill in JAVA using if and else conditions

class electricity
{
Public static Void main(String args[])
{
int unit=Integer.parseInt(args[1]);
String name=args[0];
float rupees=0.0f;
{
if (unit<100)
rupees=rupees +unit*.40;
else if(unit>100 && unit<300)
rupees=rupees+(unit-100)*.50;
else (unit>300)
rupees=rupees+(unit-300)*.60;
}
if(rupees<250)
{
System.out.println("name="+name);
System.out.println("unit="+unit+"rupees="+rupees);
}
else
{
rupees=rupees+(rupees*15)/100;
System.out.println("name="+name);
System.out.println("unit="+unit+"rupees="+rupees);
}}}

Read more ...

Program to find area of circle and cylinder in JAVA

class Area{

final float PI=3.14f;
float arac,aracy;
int r=2,h=3,l=4;
void areaofcircle()
{
arac=PI*r*r;
System.out.println("area of circle="+arac);
}
void areaofcylinder()
{
aracy=((PI*r*r*h)+(2*PI*r*l));
System.out.println("area of cylinder="+aracy);
}
}
class area2{

public static void main(String[] arg)
{
 area ob=new area();
 ob.areaofcircle();
 ob.areaofcylinder();
}
}

Read more ...