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");
}
}
Nice work Bhai
ReplyDelete