JAVA PROGRAM TO CHECK OR FIND THE WHETHER THE ENTERED STRINGS ARE EQUAL OR NOT

/*   Created by IntelliJ IDEA.
* Author: Gyanendra Yadav (Gyanendra011Yadav-coder)
* Date: 7/28/2020
* Time: 3:35 PM
* File: Lab3Task.java
*/

//Create a program in Java, to input the coupon code from a client. If the client's coupon code
// matches your already agreed upon code, then print a message to the client.


package lab3;
// 1 Import the Scanner class from the java.util package.
import java.util.Scanner;
public class Lab3Task {
public static final String DISCOUNT_CODE = "CoVid19";
public static void main(String[] args) {
// 2 Create an object of the Scanner class named 'scannerObject'.
Scanner scannerobject = new Scanner(System.in);
// 3 Input the discount code from the client and store it in a String variable named 'clientInputDiscountCode'.
System.out.println("PLEASE ENTER THE CODE:");
String clientInputDiscountCode = scannerobject.nextLine();
if (clientInputDiscountCode.isEmpty()) {
System.out.println("The coupon code cannot be empty!!");
} else {
int lengthOfUsersString = clientInputDiscountCode.length();
int length1 = DISCOUNT_CODE.length();
int length2 = clientInputDiscountCode.length();
boolean isequal = false;
if (length1 != length2) {
System.out.println("Invalid!!Code");
} else {
for (int i = 0; i < length1; i++) {
char characterOfDISCOUNTCODE = DISCOUNT_CODE.charAt(i);
char characterOfClientInputDiscountCode = clientInputDiscountCode.charAt(i);
// 4 Write an `if` statement and check whether the client input the correct discount code.
if (characterOfDISCOUNTCODE == characterOfClientInputDiscountCode) {
isequal = true;
} else {
isequal = false;
}
}
}
if (isequal == true) {
// 5 If the client's discount code was correct, print "Congrats, you get 100 off on your bill!"
System.out.println("Congrats, you get 100 off on your bill!");
} else {
System.out.println("Invalid!!Code");

}

// 6 Remove all the comments, if you have completed the steps.
}
}
}

Comments

Popular posts from this blog

PROGRAM OF CALCULATING INTERSECTION OF TWO ARRAYS

JAVA PROGRAM TO CREATE A DATABASE (SAMPLE PICTURE IS GIVEN)

Craze for Fashion