0% found this document useful (0 votes)
13 views2 pages

Java Labsheet3-3

Java

Uploaded by

tailortrendy366
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Java Labsheet3-3

Java

Uploaded by

tailortrendy366
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

(Established under the Presidency University Act, 2013 of the Karnataka Act 41 of 2013)

Course Code : CSE1006 Course Title : Problem solving using java

1) Login System with Case-Insensitive Username Check


Problem Statement:
You’re building a simple login system. The system should:
 Check if the entered username and password are valid.
 Ignore the case of the username (i.e., Sikandar is the user name).
 Ensure the password is case-sensitive. (i.e., Secure123)
 Also, the password should be at least 8 characters long.

Solution:
import java.util.Scanner;
public class LoginSystem {
public static void main(String[] args) {
// Simulated stored username and password
String storedUsername = "Sikandar";
String storedPassword = "Secure123";

Scanner scanner = new Scanner(System.in);

System.out.print("Enter username: ");


String inputUsername = scanner.nextLine();

System.out.print("Enter password: ");


String inputPassword = scanner.nextLine();

// Check password length


if (inputPassword.length() < 8) {
System.out.println("Password must be at least 8 characters.");
System.exit(0);
}
// Convert username to lower case for case-insensitive comparison
if (storedUsername.toLowerCase().equals(inputUsername.toLowerCase())) {
// Case-sensitive password comparison
if (storedPassword.equals(inputPassword)){
System.out.println("Login successful!");
System.out.println("Welcome, " + storedUsername.toUpperCase() + "!");
}
else {
System.out.println("Incorrect password.");
}
}
else {
System.out.println("Username not found.");
}
}
}
============================
2) Write a program that reads two peoples of child parent first name and suggests a name for
their child
Hint: Father name: Abhishek Bachchan
Mother name : Aishwarya Rai
Gender: female
Chile name : AISHWAABHISHEK

import java.util.*;
public class BabyName
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.print("Parent 1 father first name? ");
String fname = s.nextLine(); // amith kumar
System.out.print("Parent 2 mother first name? ");
String mname = s.nextLine(); // suhmitha sen
System.out.print("Child Gender? ");
String gender = s.next();
String f_halfName = getHalfName(fname);
String m_halfName = getHalfName(mname);
String c_name = "";
if(gender.toLowerCase().startsWith("m")) // male
{
c_name = f_halfName + m_halfName;
}
else
{
c_name = m_halfName + f_halfName;
}
System.out.println("Suggested name: " + c_name.toUpperCase());
}

static String getHalfName(String name)


{
int halfIndex = name.length() / 2;
String half = name.substring(0, halfIndex);
return half;
}
}

==========

You might also like