Aim:To make a simple java project for shoe shop using all the concept of OPPS,Exception handling and packages
Background:HI-TECH SHOE SHOP is a project made to help people buy shoes. This project was done to enhance my java programming skills and develop further knownledge on the concepts of OOPS,Exception Handling and pacakges
This project has been divided in 2 packages, the default package which contains one class(Welcome),and the other user defined package which contains 3 classes and 1 interface
Default Package: Welcome Class
import java.util.Scanner;
import assignment.Display;
public class Welcome {
static Scanner input = new Scanner(System.in);
static int y;
public static void main(String[] args)
{
pattern();
Display s = new Display();
s.Check();
pattern();
s.GetChoice(s.C);
s.GetChoice();
pattern();
s.printRecipe(s.sum);
confirmation(s.sum);
if( y==1)
{
s.printRecipe(s.name, s.itembrought, s.sum);
}
pattern();
thankyou();
}
private static void thankyou()
{
if(y==1)
{
System.out.println("\nTHANKYOU FOR CHOOSING HI-TECH SK SHOE STORE");
}
System.out.println("\nVisit us Again");
}
private static void confirmation(int x)
{
try
{
y=input.nextInt();
if( y==1)
{
pattern();
System.out.println("\nGenerating Recipt");
System.out.println("Payed Nu: " + x + " To Tazi Shoe Store on " + java.time.LocalDate.now() );
}
}
catch(Exception e)
{
pattern();
}
}
static void pattern()
{
for(int i =0; i <100;i++)
{
System.out.print("+");
}
}
}
Assignment Package: Display class
package assignment;
import java.util.InputMismatchException;
public class Display extends ItemDetails implements printingSystem
{
public int sum;
public int itembrought = 0;
int cardno;
public void GetChoice()
{
System.out.println("Enter serial Number of the item you want to buy:");
System.out.println("Press 0 to see the Total");
boolean t =true;
int x ;
while(t==true)
{
try
{
x = in.nextInt();
if(x==1 || x==5 ||x==6)
{
sum += 500;
itembrought++;
System.out.println("!!!!!!!!Added to the Cart!!!!!");
}
else if(x==2 || x==7 || x==10)
{
sum +=750;
itembrought++;
System.out.println("!!!!!!!!Added to the Cart!!!!!");
}
else if(x==3 || x==4 || x==8)
{
sum +=900;
itembrought++;
System.out.println("!!!!!!!!Added to the Cart!!!!!");
}
else if(x==9)
{
sum += 5000;
itembrought++;
System.out.println("!!!!!!!!Added to the Cart!!!!!");
}
else if(x==0)
{
t=false;
}
else
{
throw new Numberlargerexception();
}
}
catch (Numberlargerexception e)
{
System.out.print("Invalid Choice!! Please enter valid choice\n");
GetChoice();
}
catch(InputMismatchException e)
{
System.out.print("Invalid Choice!! Please enter valid choice\n");
GetChoice();
}
}
}
@Override
public void printRecipe(String nam, int iB, int Sn)
{
System.out.println("\nCustomer'sName: " + nam + "\nTotal Items Brought: " + iB + "\nTotal Nu: " + Sn + "\nDate Of Payment: " + java.time.LocalDate.now() );
}
@Override
public void printRecipe(int Sn)
{
System.out.println("\nTotal is Nu:" + Sn);
System.out.print("press 1.check out");
System.out.print("\npress any key on the board to to cancel\n");
}
}
Items details class
package assignment;
import java.util.Scanner;
public class ItemDetails
{
Scanner in = new Scanner(System.in);
public int C;
public String name;
ItemDetails()
{
System.out.print("\nPlease Enter Your name ");
checkname();
System.out.print("WELCOME " + name + " TO HI-TECH SK SHOE SHOP");
System.out.println("\nPress 1 for Men shoes\nPress 2 for Women Shoes");
}
public void GetChoice(int x)
{
if(x == 1)
menshoe();
if(x==2)
Womenshoe();
}
private void Womenshoe()
{
System.out.println("\nDisplaying Women's shoes:");
System.out.println("1.SANDAL --------------------MRP:500");
System.out.println("2.HIGH HEEL------- ----------MRP:750");
System.out.println("3.LOW HEEL-------------------MRP:900");
System.out.println("4.CASUAL OFFICE SHOES------- MRP:900");
System.out.println("5.JUMPER PINK SHOES ---------MRP:500");
System.out.println("6.MOMOS SHOES ---------------MRP:500");
System.out.println("7.PLASTIC OFFICE SHOES ------MRP:750");
System.out.println("8.PARTY SHOES ---------------MRP:900");
System.out.println("9.BOOT --------------------- MRP:5000");
System.out.println("10.FLAT SLIPPERS ------------ MRP:750");
}
private void menshoe()
{
System.out.println("\nDisplaying Men's shoes:");
System.out.println("1.NIKE BASKETBALL SHOES --------MRP:500");
System.out.println("2.PUMA BASKETBALL SHOES ------- MRP:750");
System.out.println("3.ADDIDAS BASKETBALL SHOES------MRP:900");
System.out.println("4.NIKE FOOTBALL SHOES --------- MRP:900");
System.out.println("5.PUMA FOOTBALL SHOES ----------MRP:500");
System.out.println("6.ADDIDAS FOOTBALL SHOES ------MRP:500");
System.out.println("7.GOLD TOE OFFICE SHOES -------MRP:750");
System.out.println("8.HOME SLIPPERS --------------- MRP:900");
System.out.println("9.BOOT ----------------------- MRP:5000");
System.out.println("10.VANS SHOES ---------------- MRP:750");
}
private void checkname()
{
name = in.nextLine();
try
{
char name0[]=name.toCharArray();
for(char a : name0)
{
if(Character.isDigit(a))
throw new Numberlargerexception();
}
}
catch (Numberlargerexception e)
{
System.out.print("Your name contains digit\nRe-Enter Name:");
checkname();
}
}
public void Check()
{
boolean ny = true;
while(ny == true)
{
String c = in.nextLine();
try
{
C = Integer.parseInt(c);
if(C>3 || C<1)
throw new Numberlargerexception();
ny=false;
}
catch(NumberFormatException e)
{
System.out.print("Invalid Choice!! Please enter valid choice\n");
}
catch (Numberlargerexception e)
{
System.out.print("Invalid Choice!! Please enter valid choice\n");
}
}
}
}
Numberlargerexception Class
package assignment;
public class Numberlargerexception extends Exception {
Numberlargerexception()
{
super("Error");
}
}
interface printingSystem
package assignment;
public interface printingSystem
{
void printRecipe(String nam, int iB, int Sn);
void printRecipe(int Sn);
}
output 1:
Output 2:
0 Comments:
Post a Comment