Saturday 24 June 2017

Assigning Wifi password for a new user !

Hello friends,
In today's problem we discuss about assigning a password for a hotel wifi conection based on the inputs by the user based on certain criteria !!

Conditions:

  • Length of password is to be 5 characters
  • 1st char- summation of room number(till it becomes a single digit)
  • 2nd char- 1st char of lastname (if no last name,then first name)
  • 3rd char- summation of mobile number(1 digit)
  • 4th char- random mo generated system
  • 5th char- if person is from locality then no of chars in 1stname ,if it is odd then add 1,else
  • print the last index of firstname

CODE:

package sanjay;
import java.util.*;
public class wifiassign {
static  String password="";
static int sum_of_digits(long num)
{
long sum=0;
long rem=0;
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
return (int)sum;
}
static int no_of_digits(long num)
{
int nod=0;
while(num>0)
{
num=num/10;
nod++;
}
return nod;
}
static int getRandomNumberInRange(int min, int max) {

if (min >= max) {
throw new IllegalArgumentException("max must be greater than min");
}
Random r = new Random();
return r.nextInt((max - min) + 1) + min;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String first_name="";
String middle_name="";
String last_name="";
long phno=0;
int room_no=0;
String area="";
String name="";
System.out.println("Enter the name : ");
name=sc.nextLine();
System.out.println("Enter the area(Rural/Urban) : ");
area=sc.nextLine();
System.out.println("Enter the mobile number : ");
phno=sc.nextLong();
System.out.println("Enter the room number : ");
room_no=sc.nextInt();
String names[]=name.split(" ");
int char1=sum_of_digits(room_no);
int dig1=no_of_digits(char1);
while(dig1>1)
{
char1=sum_of_digits(char1);
dig1=no_of_digits(char1);
}
password=password+char1;
password=password+names[1].charAt(0);
int char3=sum_of_digits(phno);
//System.out.println(char3);
int dig3=no_of_digits(char3);
while(dig3>1)
{
char3=sum_of_digits(char3);
dig3=no_of_digits(char3);
}
password=password+char3;
int char4=getRandomNumberInRange(0,9);
password=password+char4;
int char5=0;
int dig5=0,len=0;
if(area.equalsIgnoreCase("Rural"))
{
len=names[0].length();
if(len%2==0)
{
char5=len;
dig5=no_of_digits(char5);
while(dig5>1)
{
char5=sum_of_digits(len);
dig5=no_of_digits(char5);
}
}
else
{
char5=len+1;
dig5=no_of_digits(char5);
while(dig5>1)
{
char5=sum_of_digits(len);
dig5=no_of_digits(char5);
}
}

}
if(area.equalsIgnoreCase("Urban"))
{
len=names[0].length();
char5=len;
dig5=no_of_digits(char5);
while(dig5>1)
{
char5=sum_of_digits(len);
dig5=no_of_digits(char5);
}
}
password=password+char5;
System.out.println("Password is : "+password);
}
}

No comments:

Post a Comment

BlockChain Company Infographic

Hello All,      This post talks about the impact of blockchain technology in various standards and industrial uses. Kindly do read to know i...