Java language microproject pdf-1
Java language microproject pdf-1
Online Shopping
2.0 Rationale:
The basic application for online shopping i.e. in that user can creates his/her
account. Using this application user can shop anything what they want.
Program code-
import java.util.*;
class ShopDetails
{
private String accno;
private String name;
private long balance;
Scanner sc = new Scanner(System.in);
String id = null;
String productName = null;
int quantity = 0;
double price = 0.0;
double totalPrice = 0.0;
double overAllPrice = 0.0;
double subtotal=0.0, discount=0.0;
char choice = '\0';
ShopDetails()
{
System.out.println("__________________________________________
___________");
}
public void showAccount()
{
System.out.println("Name of account holder: " + name);
System.out.println("Account no.: " + accno);
System.out.println("Balance: " + balance);
System.out.println("__________________________________________
__________");
}
//To add balance to shoppie card
}
//displayFormat
public static void displayFormat()
{
System.out.format("__________________________________________
__________________________________________________________
______________");
System.out.print("\nProduct ID \t Name \t\t Quantity \t\tRate \t\t\t\t
TotalPrice \n");
System.out.format("__________________________________________
__________________________________________________________
______________\n");
}
// display
public void display()
{
System.out.format(" %-9s %-9s %5d %9.2f " ,id,
productName, quantity, price, totalPrice);
}
do
{
// read input values
System.out.println("Enter the product details: ");
System.out.print("Quantity: ");
quantity = sc.nextInt();
choice = sc.next().charAt(0);
//read remaining characters, don't store (no use)
sc.nextLine();
}
while
(choice == 'y' || choice == 'Y');
//display all product with its properties
ShopDetails.displayFormat();
for(ShopDetails p : product)
{
p.display();
}
//price calculation
System.out.println("\n\t\t\t\t\t\t\t\t\t\tTotal Amount (Rs.) "
+overAllPrice);
//calculating discount
discount = overAllPrice*2/100;
System.out.println("\n\t\t\t\t\t\t\t\t\t\t Discount (Rs.) " +discount);
//total amount after discount
subtotal = overAllPrice-discount;
System.out.println("\n\t\t\t\t\t\t\t\t\t\t Subtotal "+subtotal);
}
public boolean search(String ac_no)
{
if (accno.equals(ac_no))
{
showAccount();
return (true);
}
return (false);
}
}
public class Shop
{
public static void main(String arg[])
{
Scanner sc = new Scanner(System.in);
System.out.println("\t\t\t\t--------------------Invoice---------------- ");
System.out.println("\t\t\t\t\t "+" "+"Sunil Super Shop");
System.out.println("\t\t\t\t\t Dhule(devpur)");
System.out.println("GSTIN: 12AE389Y4J67WE5"+"\t\t\t\t\t\t\tContact:
(+91)1234567890\n");
do
{
System.out.println("__________________________________________
__________");
System.out.println(" 1. Display all account details \n 2. Search by
Account number\n 3. Add Balance to card \n 4.Shop Groceries \n 5.Exit
");
System.out.println("Enter your choice: ");
ch = sc.nextInt();
switch (ch)
{
case 1:
for (int i = 0; i < C.length; i++)
{
C[i].showAccount();
}
break;
case 2:
System.out.print("Enter account no. you want to search: ");
String ac_no = sc.next();
boolean found = false;
for (int i = 0; i < C.length; i++)
{
found = C[i].search(ac_no);
if (found)
{
break;
}
}
if (!found)
{
System.out.println("Search failed! Account doesn't exist..!!");
}
break;
case 3:
System.out.print("Enter Account no. : ");
ac_no = sc.next();
found = false;
for (int i = 0; i < C.length; i++)
{
found = C[i].search(ac_no);
if (found)
{
C[i].deposit();
break;
}
}
if (!found)
{
System.out.println("Search failed! Account doesn't exist..!!");
}
break;
case 4:
System.out.print("Enter Account No : ");
ac_no = sc.next();
found = false;
for (int i = 0; i < C.length; i++)
{
found = C[i].search(ac_no);
if (found)
{
System.out.print("Enter your Shopping List:");
C[i].shopping();
break;
}
}
if (!found)
{
System.out.println("Search failed! Account doesn't exist..!!");
}
break;
case 5:
System.out.println("See you soon...");
break;
}
}
while (ch != 5);
}
}
Output:
// Search account no :
//Shop Groceries & Exit.