🌙 DARK

Compare Phone Number Ebox Solution

 

COMPARE PHONE NUMBER - JAVA

Compare Phone Number


New App helps you discover great places to eat around or de-stress in all major cities across 20000+ merchants. Explore restaurants, spa & salons, and activities to find your next fantastic deal. Write a program to find the duplication of user accounts.

Write a Java program to get two users’ details and display whether their phone numbers are the same or not with the following class and methods.

[Note: Strictly adhere to the object-oriented specifications given as a part of the problem statement.
Follow the naming conventions as mentioned. Create separate classes in separate files.]


Consider the class User with the following private attributes/variables.

Date TypeVariable
String    name
String    username
String    password
Long    phoneNumber


Include appropriate getters and setters.
Prototype for the Parameterized Constructor,
public User(String name, String username, String password, Long phoneNumber)

Define the following method in the User class.

Method Name :

public boolean comparePhoneNumber(User user)

Description:

In this method compare the phone number of the two users and
return true if both the numbers are equal else return false


Consider the Main class and write the main method to test the above class.

In the main method

  •     Obtain the details of the user.
  •     Create an object for the User class using the parameterized constructor(name, username, password, phoneNumber).
  •     Call the method comparePhoneNumber() in the Main class.

 



Input and Output Format

Refer sample input and output for formatting specifications.
If both phone numbers are the same then print “Same Users” else print “Different Users”.
The output should be printed in the Main class.


Sample Input/Output 1:
[All text in bold corresponds to the input and the rest corresponds to output.]

Enter Name
john
Enter UserName
john@123
Enter Password
john@123
Enter PhoneNumber
9092314562
Enter Name
john
Enter UserName
john@12
Enter Password
john@12
Enter PhoneNumber
9092314562
Same Users


Sample Input/Output 2:

Enter Name
william
Enter UserName
william####
Enter Password
william
Enter PhoneNumber
9092314562
Enter Name
john
Enter UserName
john@123
Enter Password
john@123
Enter PhoneNumber
9092312102
Different Users

Create two classes 1) Usser

2) Main


PROGRAMS :

public class User {
        private String name;
        private String username;
        private String password;
        private long phoneNumber;
        
        public User(String name,String username,String password,long phoneNumber){
            this.name = name;
            this.username = username;
            this.password = password;
            this.phoneNumber = phoneNumber;
            
        }
        public String getName(){
         return name;   
        }
        
        public void setName(String name){
            this.name = name;
        }
        public String getusername(){
            return username;
        }
        public void setUsername(String username){
            this.username = username;
        }
        public String getPassword(){
            return password;
        }
        public void setPassword(String password){
            this.password = password;
        }
        public long getPhoneNumber(){
            return phoneNumber;
        }
        public void setPhoneNumber(long phoneNumber){
            this.phoneNumber = phoneNumber;
        }
    
    boolean flag = false;
public boolean comparePhoneNumber(User user) {

        if(user.phoneNumber==phoneNumber)
            flag = true;
        return flag;
}


import java.io.*;
import java.util.Scanner;
class Main{
    public static void main(String[] args) throws Exception{     

        Scanner sc = new Scanner(System.in);
      String name,username,password;
        long phoneNumber;
        
        System.out.println("Enter Name");
        name = sc.nextLine();
        
        System.out.println("Enter UserName");
        username = sc.nextLine();
        
        System.out.println("Enter Password");
        password = sc.nextLine();
        
        System.out.println("Enter PhoneNumber");
        phoneNumber = sc.nextLong();
        
        sc.nextLine();
        User user1 = new User(name,username,password,phoneNumber);
        
System.out.println("Enter Name");
        name = sc.nextLine();
        
        System.out.println("Enter UserName");
        username = sc.nextLine();
        
        System.out.println("Enter Password");
        password = sc.nextLine();
        
        System.out.println("Enter PhoneNumber");
        phoneNumber = sc.nextLong();
        
        
        User user2 = new User(name,username,password,phoneNumber);
        
        if(user1.comparePhoneNumber(user2))
            System.out.println("Same Users");
        else
            System.out.println("Different Users");
        
}
    
}






Array


Write a Java program to display the array of Integers and array of Strings. Use for each loop to iterate and print the elements.
 

Constraints :

Use for each loop to iterate and print the elements.
 

Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.


Sample Input and Output :
 

Enter n :
3
Enter numbers : 
100
23
15

Enter strings : 
hi
hello
welcome

Displaying numbers
100
23
15
Displaying strings
hi
hello
welcome



Problem Requirements:

Java

KeywordMin CountMax Count
for14

Solution:

import java.io.*; 
import java.util.*; 
public class Main{ 
public static void main (String[] args) throws Exception{ 
        Scanner sc = new Scanner(System.in);
    System.out.println("Enter n :");
int length = sc.nextInt();
{
int[] massage = new int[length];
System.out.println("Enter numbers :");
for(int i=0; i<length; i++) {
System.out.print("");
massage[i] = sc.nextInt();
}
String[] name = new String[length];
System.out.println("Enter strings :");
for(int j=0; j<length; j++) {
System.out.print("");
name[j] = sc.next();
}
System.out.println("Displaying numbers");
for(int i=0; i<length; i++) {
System.out.print(massage[i]+"\n");
}
        System.out.println("Displaying strings");
for(int j=0; j<length; j++) {
System.out.print(name[j]+"\n");
}
}
}

 


COMMAND LINE ARGUMENT - COUNT

Command Line Argument - Count

Write a program to accept strings as command-line arguments and print the number of arguments entered.


Sample Input (Command Line Argument) 1:
Command Arguments

Sample Output 1:

Arguments :
Command
Arguments
The number of arguments is 2

 

Sample Input (Command Line Argument) 2:
Commands

Sample Output 2:

Arguments :
Commands
The number of arguments is 1

 


Program:



public class Main{
    public static void main(String[] args)
    {         
         int count = 0;
         System.out.println("Arguments :");
         for(int i=0;i<args.length;i++) 
         {
            System.out.println(args[i]);
      
            count++;
         }
     
       System.out.println("The number of arguments is "+count);
    }
}








Post a Comment

Thanks for reading the blog. We hope it was useful to you and that you learned something new. Will always be writing on new and interesting topics, so you can visit our website to know the latest updates of our blogs. Thank You!

Previous Post Next Post

Contact Form