.

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");
}

}
}

No comments:

Post a Comment