Showing posts with label Project. Show all posts
Showing posts with label Project. Show all posts

WAP in Java Using all the concepts of OOP, Exception handling and Packages -II

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:



WAP in Java Using all the concepts of OOP,Exception handling and Packages -I

Aim: To create a program to allow people to register for credit management system and print their information and prompt user to register for the program.

Background: Credit management system program is made to help people register for a system and hence it can be implement as a backend code for many programs be it bank system, blood donation systems, school admission system and many more other systems. The codes contains complete information and also the password is set to private to ensure security. Almost all the parameters have exception handling and hence it ensures all the information given by the user is correct up to some level.
Objective: To allows users to register for a system and print their details and ask for confirmation for registration


Code Explaination: There are 2 packages default package and register package

mainBody Class

it contains 3 methods and the main method is present here

import java.util.Scanner;

import register.ShopRegis;
import register.StudentRegister;

public class mainBody  {
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args)
	{	
		Intro obj = new Intro();
		String x = s.nextLine();
		obj.choose(x);
		if(obj.y==1)
		{
			StudentRegister s1 = new StudentRegister();
			s1.getname();
			s1.getSname();
			s1.Studentno();
			s1.Collegename();
			s1.emailadress();
			s1.setPassword(null);
			for(int i =0;i<50;i++)
			{
				if(i==25)
				System.out.print("Showing Details");
				else
					System.out.print("*");
			}
			obj.showDetails(s1.name,s1.Sname,s1.snum, s1.strnum, s1.email,s1.getPassword());
			Sure();
		}
		else if(obj.y==2)
		{
			ShopRegis s1 = new ShopRegis();
			s1.getname();
			s1.getSname();
			s1.phonenum();
			s1.Lis();
			s1.Location();
			s1.setPassword(null);
			for(int i =0;i<50;i++)
			{
				if(i==25)
				System.out.print("Showing Details");
				else
					System.out.print("*");
			}
			
			obj.showDetails(s1.name,s1.Sname,s1.p, s1.Lnum,s1.phone,s1.getPassword());
			Sure();
			
		}
		else
		{
			finalmessage();
		}
		
		
	}
	private static void Sure()
	{
		for(int i =0;i	<50;i++)
		{
			if(i==25)
			System.out.print("Are you Sure you want to register");
			else
				System.out.print("*");
		}
		           System.out.println("\n                       press 1 to register else press anybutton");
					String co = s.nextLine();
					try
					{
						int x =Integer.parseInt(co);
						if(x==1)
						{
							for(int i =0;i	<50;i++)
							{
								if(i==25)
									System.out.print("Registered");
								else
									System.out.print("*");
							}
						}
						
						else
							{
							for(int i =0;i	<50;i++)
							{
								if(i==25)
									System.out.print("Not-Registered");
								else
									System.out.print("*");
							}		
							}
						finalmessage();
					}
					catch(NumberFormatException e)	
					{
						for(int i =0;i	<50;i++)
						{
							if(i==25)
								System.out.print("Not-Registered");
							else
								System.out.print("*");
						}
						finalmessage();
					}
	}
	private static void finalmessage()
	{
		System.out.print("\n");
		for(int i =0; i	<55; i++)
		{
			if(i == 20)
				System.out.print("Thankyou For Using Our Service");
			else
				System.out.print("*");
		}
		
		
	}		
}
 

invalidinputException

it contain a constructor and whenever an custom made Exception is catched in the default package the program comes to this method

public class invalidinputException extends Exception {
	invalidinputException()
	{
		super("Invalid Input");
	}
}

Intro Class

This class contains 3 methods and 1 constructor, it implements an interface

import java.util.Scanner;

public class Intro implements Details {
	String name,em,Pa;
	int  Stdno;
	int y = 0;
	Intro()
	{
		for(int i = 0; i	<50;i++)
		{
			if(i==20)
				System.out.print("Welcome to Credit management System");
			else
			System.out.print("*");
		}
		System.out.println("\nPress 1. for student  Registration \nPress 2. for customer Registration \npress 0. to  cancel   Registration");
		
		
	}
	public int choose( String x)
	{
		
		Scanner s = new Scanner(System.in);
		{
			 try 
			 {
				 y = Integer.parseInt(x);
				 if(y!=1 && y!=2 && y!=0)
					 throw new invalidinputException();
				 return y;	 
			 }
			 catch(invalidinputException e)
			 {
				 System.out.print("Invalid input");
				 String X = s.nextLine();
					choose(X);
			 }
			 catch(NumberFormatException e)
			{
				System.out.println("Invalid Input");
				String X = s.nextLine();
				choose(X);
				
			}
		}
		return y;		
	}		
	@Override
	public void showDetails(String fn, String sn, String snum, int Sn, String em, String pas) {
		
		 name = fn + sn;
		  System.out.println("\n1.Name:" + name +  "\n2.Student Number:" + Sn   + "\n3.College name:" + snum + "\n4.EmailAdress:" + em  + "\n5.password:" + pas   );
			
	}
	public void showDetails(String fn, String sn, String Loc, int Ln, int pn, String pas)
	{
		 name = fn + sn;
		  System.out.println("\n1.Name:" + name +  "\n2.Liscence No:" + Ln   + "\n3.Adress:" + Loc  + "\n4Phone Number:"+ pn + "\n5.password:" + pas   );
	}
 }

Interface Details

This interface contains two methods


public interface Details {
	void showDetails(String fn, String sn, String Loc, int Ln, int pn, String pas);
	void showDetails(String fn, String sn, String snum, int Sn, String em, String pas);
	
}

Under the register package there are 4 classes

1 class contains common registration parameter other 2 contains parameters different for student and canteen owners and the clas class implements the exception

Common_Registration

package register;

import java.util.Scanner;


public class Common_Register 
{
	Scanner s = new Scanner(System.in);
	public String name;
	public String Sname;
	private String Password;
	
	public void getname()
	{
		System.out.print("Enter Your First Name:");
		name = s.nextLine();
		try 
		{
			for(int i =0; i	<name.length(); i++)
			{
				for(char j =0; j	<65 ; j++ )
				{
					
					if(name.charAt(i) == j)
					{
					   throw new ErrorException();
					}
					
				}
			}
		}
		catch (ErrorException e)
		{
			System.out.println("Please enter name Correctly");
			getname();
		}
}
	public void getSname()
	{
		System.out.print("Enter Your Second Name:");
		Sname = s.nextLine();
		try 
		{
			for(int i =0; i	<Sname.length(); i++)
			{
				for(char j =0; j	<65 ; j++ )
				{
					
					if(Sname.charAt(i) == j)
					{
					   throw new ErrorException();
					}
					
				}
			}
		}
		catch (ErrorException e)
		{
			System.out.println("Please enter name Correctly");
			getSname();
		}
		catch(Exception e)
		{
			System.out.println("Please enter name Correctly");
			getSname();
		}
	}
	public String getPassword() {
		return Password;
	}
	public void setPassword(String password) 
	{
		 String np = null;
		{
			while(password == null)
			{
				System.out.print("Enter Password:");
				password = s.nextLine();
				 if(password.length()	<8 )
				   {
					System.out.println("Password is too weak");
						setPassword(null);
				  }
				 else 
				 {
					 
					 System.out.print("Re-Enter Password:");
					 np = s.nextLine();
					 checkpassword(password,np);
				 }
				
					
			}
			
		}
	}
	private void checkpassword(String password2, String np)
	{
		if(password2.matches(np))
		{
			this.Password = password2;
		}
		else
		{
			System.out.print("PASSWORD MISMATCH\n");
			setPassword(null);
			
		}
	}		
}

ShopRegis class

package register;

public class ShopRegis extends Common_Register
{
	public String p;
	public int phone;
	public int Lnum;
		public void phonenum()
		{
			boolean choice =true;
			while(choice == true)
			{
				System.out.print("Enter your Phone number:");
				p = s.nextLine();
				try
				{
					phone = Integer.parseInt(p);
					if(phone/100000000 > 1 || phone/10000000!=1 &&  phone/10000000!=7 || phone/1000000!=17 && phone/1000000 !=77 )
					{
						throw new ErrorException();
					}
					else
					choice = false;
				}
				catch(NumberFormatException e)
				{
					System.out.println("Invalid phone number");
				}
				catch(ErrorException e)
				{
					System.out.println("Invalid phone number");
				}
			}
			
		}
		public void Lis()
		{
			boolean choice =true;
			while(choice == true)
			{
				System.out.print("Enter your Liscence number:");
				p = s.nextLine();
				try
				{
					Lnum= Integer.parseInt(p);
					choice = false;
				}
				catch(NumberFormatException e)
				{
					System.out.println("Invalid Liscence number");
				}
				
			}			
		}
		public void Location()
		{
			System.out.print("Enter your Canteen Location:");
			p=s.nextLine();
		}
}

StudentRegister Class

package register;


public class StudentRegister extends Common_Register  
{
	public String snum;
	public int strnum;
	public String email;
	boolean check = false;
	public void Studentno()
	{
		
		while(check == false)
		{
			System.out.print("Enter Student Number:");
				snum = s.nextLine();
				
			try
			{
				strnum = Integer.parseInt(snum);
				check = true;
			}
			catch(Exception e)
			{
				System.out.println("Student number should be an integer value!!");
				
			}
			
		}
		
	}
	public void Collegename()
	{
		System.out.print("Enter Your college's Abbreviation:");
		snum = s.nextLine();
		try
		{
			for(int i =0;i	<snum.length();i++)
			{
				for(char j =0; j	<65 ; j++)
					if(snum.charAt(i) == j)
					{
						throw new ErrorException();
					}
			}
		}
		catch(ErrorException e)
		{
			System.out.println("Invalid College Name");
			Collegename();
		}
			
	}
	public void emailadress()
	{
		while(check == true)
		{
			System.out.print("Enter Your  Email Adress:");
			email = s.nextLine();
			for(int i =0;i	<email.length();i++) {
				if(email.charAt(i) == '@')
				{
				   check = false;
				}	
			}
			if(check == true)
			{
				System.out.println("Email adress should contain @");
				emailadress();
			}		
		}
					
	}
}

ErrorException

package register;

public class ErrorException extends Exception
{
	public ErrorException()
	{
		super("Error");
	}
}

OUTPUTS: