Java CSV printing relevant information in relation to User input - java

my current code:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
public class Menu {
private static final String DEFAULT_DATE_FORMAT = "MM/dd/yyyy";
public static void main(String[] args) {
boolean exit = false;
int userInputt;
do {
userInputt = printMenu();
switch(userInputt) {
case 1:
inputLocation();
break;
case 2:
inputType();
break;
case 3:
inputRating();
break;
case 4:
System.out.println("Goodbye!");
exit = true;
break;
default:
System.out.println("Invalid Option.");
break;
}
}
/* an int varible that allows the storing of an integer */
while(userInputt > 4);
}
/* an int varible that allows the storing of an integer */
public static int printMenu () {
int selection;
Scanner sc = new Scanner (System.in);
System.out.println("Welcome to Melbnb!");
System.out.println("------------------------------------------------");
System.out.println("> Select from main menu");
System.out.println("------------------------------------------------");
System.out.println(" 1) Search by location");
System.out.println(" 2) Browse by type of place");
System.out.println(" 3) Filter by rating");
System.out.println(" 4) Exit");
System.out.print("Please Select: ");
selection = sc.nextInt();
return selection;
}
private static char inputLocation() {
Scanner userInput = new Scanner(System.in);
File file = new File("C:/Users/andys/OneDrive/Desktop/Melbnb (2).csv");
String fileData = "";
try (Scanner reader = new Scanner(file)) {
// Read the header line so we don't deal with it again
fileData = reader.nextLine();
System.out.print("Please provide a location: ");
String location1 = userInput.nextLine().trim();
List<String> foundRecords = new ArrayList<>();
boolean found = false;
while (reader.hasNextLine()) {
fileData = reader.nextLine().trim();
// Skip blank lines (if any).
if (fileData.isEmpty()) {
continue;
} String regex = ",";
String[] lineParts = fileData.split(regex);
found = (location1.isEmpty() ||
(lineParts[0].contains(location1) ||
(location1.isEmpty() ||
(lineParts[1].contains(location1)))));
if (found) {
foundRecords.add(fileData);
found = false;
}
}
// Display found records (if any)
System.out.println();
System.out.println("Found Records:");
System.out.println("====================================");
if (foundRecords.isEmpty()) {
System.out.println(" No Records Found!");
}
else {
for (String str : foundRecords) {
System.out.println(str);
}
}
System.out.println("====================================");
}
catch (FileNotFoundException ex) {
}
char userInputt;
do {
userInputt = location();
switch(userInputt) {
case 1:
System.out.println("------------------------------------------------");
break;
case 2:
inputType();
break;
case 3:
inputRating();
break;
case 4:
printMenu();
break;
default:
break;
}
}
while(userInputt > 4);
return userInputt;
}{
}
private static char location() {
// TODO Auto-generated method stub
return 0;
}
private static void inputType() {
System.out.println("------------------------------------------------");
}
private static void inputRating() {
}
/* ---------------------------------- Locations ---------------------------------- */
private static void Southbank() {
int southbankPrice = 42;
int southbankClean = 11;
int southbankService = 10;
double southbankDiscount = 0.05;
Scanner checkIn = new Scanner (System.in);
System.out.println("------------------------------------------------");
System.out.println("> Provide dates");
System.out.println("------------------------------------------------");
System.out.print("Please provide check-in date (dd/mm/yyyy): ");
Date inDate = getInputDate(checkIn);
System.out.print("Please provide checkout date (dd/mm/yyyy): ");
Date outDate = getInputDate(checkIn);
System.out.println("------------------------------------------------");
Scanner pInfo = new Scanner (System.in);
System.out.println("> Provide personal information");
System.out.println("------------------------------------------------");
System.out.print("Please provide your given name: ");
String southName = pInfo.nextLine();
System.out.print("Please provide your surname: ");
String southLast = pInfo.nextLine();
System.out.print("Please provide your email address: ");
String southEmail = pInfo.nextLine();
System.out.print("Please provide number of guests: ");
String southGuest = pInfo.nextLine();
System.out.print("Confirm and pay (Y/N): ");
String southConfirm = pInfo.nextLine();
System.out.println("------------------------------------------------");
System.out.println("> Show property details");
System.out.println("------------------------------------------------");
System.out.printf("%-25s%-20s\n", "Property:","Private room in the heart of Southbank hosted by " + southName);
System.out.printf("%-25s%-20s\n", "Type of place:","Private room");
System.out.printf("%-25s%-20s\n", "Location:","Southbank");
System.out.printf("%-25s%-20s\n", "Rating:","4.5");
System.out.printf("%-25s%-20s\n", "Description:","The apartment is situated in the heart of Southbank with an easy access to shops and cafes. It has a warm and spacious living room with an amazing view of the gardens.");
System.out.printf("%-25s%-20s\n", "Number of guests: ", southGuest);
System.out.printf("%-25s%-20s\n", "Price:", "asd");
System.out.printf("%-25s%-20s\n", "Discounted price:","asd");
System.out.printf("%-25s%-20s\n", "Service fee:","asd");
System.out.printf("%-25s%-20d\n", "Cleaning fee: ", southbankClean );
System.out.printf("%-25s%-20s\n", "Total:","asd");
}
/* ---------------------------------- Date Validation ---------------------------------- */
private static Date getInputDate(final Scanner checkIn) {
try {
return new SimpleDateFormat(DEFAULT_DATE_FORMAT).parse(checkIn.nextLine());
} catch (ParseException ex) {
System.out.println("Invalid Date. Please Try again!");
Southbank();
}
return null;
}
}
The first image is my Desired output
The second is my current output
and the third image is my CSV
My program has a feature which will allow the user to a hotel apartment by inputting a specific location for example 'South', as shown in the screenshots of my current output once the term 'South' gets inputted to prints out all the columns for any fields relating to the search term in the CSV file, However i only want the first column to be printed out. How can i achieve this output?
What can i do to achieve my desired output?
I have tried removing the 'for' statement in the following code and replacing the print element with foundrecords.get(0)

Related

NoSuchElementException ocurring inside the code

Here , I have used two classes to combine the concept of Serialization & Deserialization and Collections.
When I run the program , i get a runtime exception "NoSuchElementException".
I have used the Employee class to store the basic info of an Employee.
The class DemoEmployee is the main class in which four methods are declared.
To add an employee's info (it's object to the Linked List object I created).
To display the info of all the Employee class objects present in the Linked List object.
To serialize the Linked List object
To deserialize the Linked List object
How to resolve this issue?
import java.io.Serializable;
public class Employee_6033 implements Serializable {
private int empid_6033;
private String empname_6033;
private String empdes_6033;
private int empsalary_6033;
public Employee_6033(int empid_6033, String empname_6033, String empdes_6033, int empsalary_6033) {
// TODO Auto-generated constructor stub
this.empid_6033 = empid_6033;
this.empname_6033 = empname_6033;
this.empdes_6033 = empdes_6033;
this.empsalary_6033 = empsalary_6033;
}
int getEmpId_6033() {
return empid_6033;
}
String getEmpName_6033() {
return empname_6033;
}
String getEmpDes_6033() {
return empdes_6033;
}
int getEmpSalary_6033() {
return empsalary_6033;
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class DemoEmployee_6033 {
static List<Employee_6033> l_6033 = new LinkedList<Employee_6033>();
int n_6033;
int i_3033;
void addEmployee_6033() {
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of employees : ");
n_6033 = input.nextInt();
for (i_3033 = 1; i_3033 <= n_6033; i_3033++) {
System.out.println("\nEnter Employee " + i_3033 + "'s Details :");
System.out.print("\tEnter ID : ");
int id_6033 = input.nextInt();
input.nextLine();
System.out.print("\tEnter Name : ");
String name_6033 = input.nextLine();
System.out.print("\tEnter Designation : ");
String des_6033 = input.nextLine();
System.out.print("\tEnter Salary : ");
int salary_6033 = input.nextInt();
l_6033.add(new Employee_6033(id_6033, name_6033, des_6033, salary_6033));
}
input.close();
}
void display_6033() {
int j_6033 = 1;
for (Employee_6033 ref_6033 : l_6033) {
System.out.println("Employee " + j_6033);
System.out.println("\tID : " + ref_6033.getEmpId_6033());
System.out.println("\tName : " + ref_6033.getEmpName_6033());
System.out.println("\tDesignation : " + ref_6033.getEmpDes_6033());
System.out.println("\tSalary : " + ref_6033.getEmpSalary_6033());
j_6033++;
}
}
void serialize_6033() {
try {
String filename_6033 = "";
Scanner input = new Scanner(System.in);
System.out.print("Enter the name of the file you want to Read from : ");
filename_6033 = input.nextLine();
// Saving of object in a file
FileOutputStream file_6033 = new FileOutputStream(filename_6033);
ObjectOutputStream out_6033 = new ObjectOutputStream(file_6033);
// Method for serialization of object
out_6033.writeObject(l_6033);
out_6033.close();
file_6033.close();
System.out.println("Object has been serialized");
input.close();
}
catch (IOException ex) {
System.out.println("IOException is caught");
}
}
void deserialize_6033() {
l_6033 = null;
try {
String filename_6033;
Scanner input = new Scanner(System.in);
System.out.print("Enter the name of the file you want to Write to : ");
filename_6033 = input.nextLine();
// Reading the object from a file
FileInputStream file_6033 = new FileInputStream(filename_6033);
ObjectInputStream in_6033 = new ObjectInputStream(file_6033);
// Method for deserialization of object
l_6033 = (List<Employee_6033>) in_6033.readObject();
in_6033.close();
file_6033.close();
System.out.println("Object has been deserialized ");
display_6033();
input.close();
}
catch (IOException ex) {
System.out.println("IOException is caught");
}
catch (ClassNotFoundException ex) {
System.out.println("ClassNotFoundException is caught");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
DemoEmployee_6033 de_6033 = new DemoEmployee_6033();
int choice_6033;
do {
System.out.println("\n********* MENU *********");
System.out.println("--------------------------");
System.out.println("1. Add Employee");
System.out.println("2. Display Employee Details");
System.out.println("3. Write Data into a File - Serialization");
System.out.println("4. Read Data from a File - Deserialization");
System.out.println("5. Exit");
System.out.println("--------------------------");
System.out.print("Enter you Choice : ");
choice_6033 = input.nextInt(); //Error comes here after 1 iteration.
switch (choice_6033) {
case 1:
de_6033.addEmployee_6033();
break;
case 2:
de_6033.display_6033();
break;
case 3:
de_6033.serialize_6033();
break;
case 4:
de_6033.deserialize_6033();
break;
case 5:
break;
default:
System.out.println("You have entered an invalid choice!");
break;
}
} while (choice_6033 != 5);
input.close();
}
}
NoSuchElementException is thrown, because you call input.close() extensively, where in your case it should be called only once. I have removed input.close(); occurrences (except main method) and your code worked fine.
There reason for this that calling Scanner.close() will in fact close whole System.in and every future related method calls, like input.nextInt() in your case, will result in Exception.

Method to Find ArrayList Index to Where the Object Will be Added

I have an ArrayList that is being filled with customer information using a Customer class. In my addCustomerRecord method, I am calling findAddIndex within the addCustomerRecord method so the data entered will be sorted prior to displaying the data. Here is my code and do not mind the fileWhatever method, I don't use it.
public class CustomerDemo
{
//arrayList of customer objects
public static ArrayList<Customer> customerAL = new ArrayList<>();
public static void main (String[] args)
{
//to hold menu choice
String menuChoice = "";
Scanner kb = new Scanner(System.in);
System.out.println("To add a record press 'A': \n"
+ "to display all records press 'D': \n"
+ "to exit press 'Q': \n");
//loop priming read
menuChoice = kb.nextLine();
//make input case insensitive
menuChoice = menuChoice.toLowerCase();
do
{
if(menuChoice.equals("a"))
addCustomerRecord(kb);
else if(menuChoice.equals("d"))
{
displayCustomerRecords();
}
else if(menuChoice.equals("q"))
{
System.out.println("Program exiting..");
System.exit(0);
}
else
{
System.out.println("incorrect entry. Please re-enter a valid entry: \n");
menuChoice = kb.nextLine();
menuChoice = menuChoice.toLowerCase();
}
System.out.println("To add a record press 'A': \n"
+ "to display all records press 'D': \n"
+ "to exit press 'Q': \n");
menuChoice = kb.nextLine();
menuChoice = menuChoice.toLowerCase();
}while(menuChoice.equals("a") || menuChoice.equals("d") || menuChoice.equals("q"));
kb.close();
}
/* public static void displayCustomerRecords()
{
System.out.println();
for (int i = 0; i < customerAL.size(); ++i)
{
System.out.printf("%-15s", customerAL.get(i).getLastName());
System.out.printf("%-15s", customerAL.get(i).getFirstName());
System.out.printf("%-6s", customerAL.get(i).getCustID());
System.out.printf("%15s\n", customerAL.get(i).getPhoneNumber());
}
System.out.println();
}
/**
* prompts to enter customer data and mutator methods called
* with a Scanner object passed as an argument to set data
* #param location index position of where the element will be added.
* #param kb a Scanner object to accept input
*/
public static void addCustomerRecord(Scanner kb)
{
Customer currentCustomerMemoryAddress = new Customer();
System.out.println("Enter first name: \n");
String fName = kb.nextLine();
currentCustomerMemoryAddress.setFirstName(fName);
System.out.println("Enter last name: \n");
String lName = kb.nextLine();
currentCustomerMemoryAddress.setLastName(lName);
System.out.println("Enter customer phone number: \n");
String pNum = kb.nextLine();
currentCustomerMemoryAddress.setPhoneNumber(pNum);
System.out.println("Enter customer ID number: \n");
String ID = kb.nextLine();
currentCustomerMemoryAddress.setCustID(ID);
int addLocation = findAddLocation(currentCustomerMemoryAddress);
customerAL.add(addLocation, currentCustomerMemoryAddress);
currentCustomerMemoryAddress = null;
}
public static int findAddLocation(Customer cust)
{
int location = 0;
if(!customerAL.isEmpty())
{
for(int i = 0; i < customerAL.size(); i++)
{
//Stumped here
}
}
else
return location;
return location;
}
}
It looks like you are reinventing the wheel here William
Replace your code for displayCustomerRecords with this:
public static void displayCustomerRecords()
{
System.out.println();
customerAL.stream().map(c -> String.format("%-15s%-15s%-6s%15s\n",
c.getLastName(), c.getFirstName(), c.getCustID(), c.getPhoneNumber()))
.sorted()
.forEach(System.out::print);
System.out.println();
}
Update
Taking into account your comment you can replace your findAddLocationmethod by the following:
private static Comparator<Customer> comparator = Comparator.comparing(Customer::getLastName)
.thenComparing(Customer::getFirstName)
.thenComparing(Customer::getCustID)
.thenComparing(Customer::getPhoneNumber);
public static int findAddLocation(Customer cust)
{
int location = 0;
if(!customerAL.isEmpty())
{
for(Customer customerInList : customerAL)
{
if(comparator.compare(customerInList, cust) > 0) {
break;
}
location++;
}
}
return location;
}
We are traversing the array using Java's enhanced for-loop and comparing the objects using a Java 8 declared comparator (which I believe is the key to this assignment).
It would be a good idea if you could look into the Comparable interface and implement it in your Customer class. That way you could simply do a simple call to customerInList.compareTo(cust) to compare both objects.
As already stated, this is not a good practice and shouldn't be used in production code.

Error in reading Input from DataInputStream in java

Firstly I have made a folder named juet and then I have made two packages inside that folder. First one is Student package which takes care of all the students in university
package juet.stud;
import java.io.IOException;
import java.io.DataInputStream;
public class Student {
String name;
public int roll_no;
int std;
char grade;
public Student() {
try (DataInputStream in = new DataInputStream(System.in)) {
System.out.println("Enter name of student:");
name = in.readUTF();
System.out.println("Enter roll no.:");
roll_no = in.readInt();
System.out.println("Enter std:");
std = in.readInt();
System.out.println("Enter grade");
grade = in.readChar();
} catch (IOException e) {
System.err.println(e);
}
}
public void showInfo() {
System.out.println("Name of student: " + name);
System.out.println("Roll no.: " + roll_no);
System.out.println("Std: " + std);
System.out.println("Grade: " + grade);
}
}
Another package which I have made is Staff which takes care of all staff in the university
package juet.staff;
import java.io.IOException;
import java.io.DataInputStream;
public class Staff {
public int id;
String name, specialization;
char group;
public Staff() {
try (DataInputStream in = new DataInputStream(System.in)) {
System.out.println("Enter id:");
id = in.readInt();
System.out.println("Enter name:");
name = in.readUTF();
System.out.println("Enter area of specialization:");
specialization = in.readUTF();
System.out.println("Enter group");
group = in.readChar();
} catch (IOException e) {
System.err.println(e);
}
}
public void showInfo() {
System.out.println("ID: " + id);
System.out.println("Name: " + name);
System.out.println("Area of specialization: " + specialization);
System.out.println("Group: " + group);
}
}
And then at the last I have made MyUniversity Class in which I was using both the packages
package juet;
import juet.stud.Student;
import juet.staff.Staff;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.Console;
class University {
Student[] stu;
Staff stf[];
int studCount, staffCount;
University() {
try (DataInputStream in = new DataInputStream(System.in)) {
System.out.println("Enter capacity for students:");
int x = Integer.parseInt(in.readLine());
//stu = new Student[x];
System.out.println("Enter capacity for staff:");
x = Integer.parseInt(in.readLine());
stf = new Staff[x];
studCount = staffCount = 0;
} catch (IOException e) {
System.err.println(e);
}
}
void newStudent() {
stu[studCount] = new Student();
studCount++;
}
void studInfo(int roll
) {
int i;
for (i = 0; i < studCount; i++) {
if (stu[i].roll_no == roll) {
stu[i].showInfo();
return;
}
}
System.out.println("No match found.");
}
void newStaff() {
stf[staffCount] = new Staff();
staffCount++;
}
void staffInfo(int id
) {
int i;
for (i = 0; i < staffCount; i++) {
if (stf[i].id == id) {
stf[i].showInfo();
return;
}
}
System.out.println("No match found.");
}
}
class MyUniversity {
public static void main(String args[]) throws IOException {
University juet = new University();
int ch;
DataInputStream in = new DataInputStream(System.in);
while (true) {
System.out.println("\tMAIN MENU\n");
System.out.println("1. Add student\n2. Add staff member\n3. Display info about specific student\n4. Display info about specific staff member\n0. Exit\n\tEnter your choice");
try {
ch = Integer.parseInt(in.readLine());
switch (ch) {
case 1:
juet.newStudent();
break;
case 2:
juet.newStaff();
break;
case 3:
System.out.println("Enter roll no. of student to display info:");
int roll = in.readInt();
juet.studInfo(roll);
break;
case 4:
System.out.println("Enter ID of staff member to display info:");
int id = in.readInt();
juet.staffInfo(id);
break;
case 0:
return;
default:
System.out.println("Incorrect choice.");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Problem is arising when I am calling University object in the main class it is asking for two inputs
1).Enter capacity for students
so I enter 3
and again it ask for
2)Enter capacity for staff
But when I enter the integer there it is running infinite times
and showing error
java.io.Exception:Stream closed
at
java.io.BufferedInputStream.getBufIfopen(BufferedInputStream.java:170)
atjuet.MyUniversity.main(MyUniversity.java:76)
at java.io.DataInputStream.readLine(DataInputStream.java:513)
Please help me Thanks in advance
You are using the wrong class. DataInputStream and the methods readUTF() and readInt() can not be used for reading text from the console. It is designed to read binary content encoded by a different Java program using DataOutputStream.
The following question and answers show you how to do it right:
How can I read input from the console using the Scanner class in Java?

constructor ConferenceRooms in class ConferenceRooms cannot be applied to given types;

Can't figure out this compiling error...
import java.util.*;
import java.util.Scanner;
import java.io.*;
/**
* Write a description of class Bookings here.
*
* #author (your name)
* #version (a version number or a date)
*/
public class Bookings
{
int day = 5;
int hour = 8;
boolean RunMeOnce = false;
Scanner input = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
String fileName;
ConferenceRooms[] conRoom = new ConferenceRooms[3]; // 0 = room 1, 1 = room 2, 2 = room 3
MeetingRooms[] meetRoom = new MeetingRooms[3];
OfficeRooms[] offRoom = new OfficeRooms[3];
public Bookings(String [] args){
}
public void main(){
if (RunMeOnce = false)
{
for(int i=0; i<3; i++){
conRoom[i] = new ConferenceRooms(); //<<<<<<< ERROR OCCURS HERE
meetRoom[i] = new MeetingRooms();
offRoom[i] = new OfficeRooms();
}
RunMeOnce = true;
}
System.out.println("Hello and welcome to One Trinity Greens Room Booking, please choose an option from the list below.");
System.out.println("1. View availabile rooms");
System.out.println("2. Make a booking");
System.out.println("3. Amend a booking");
System.out.println("4. Delete a booking");
int selection = input.nextInt();
switch(selection){
case 1:
for(int i=0; i<3; i++){
System.out.println("Conference Rooms " + i+1);
conRoom[i].conferenceBookings();
System.out.println("Meeting Rooms " + i+1);
meetRoom[i].meetingBookings();
System.out.println("Office Rooms " + i+1);
offRoom[i].officeBookings();
}
break;
case 2:
break;
case 3:
break;
case 4:
break;
}
}
public void searchRooms(){
}
public void accessAvailability(){
}
public void viewBookings(){
}
public void searchBusiness(){
}
public void addBooking(){
}
public void deleteAllBookings(){
}
public void amendBooking(){
}
public void cancelBooking(){
}
}
public ConferenceRooms(String pbusinessName, String proomType, String pavailability, String proomInformation, String pmeetingBookings){
super(pbusinessName, proomType, pavailability);
roomInformation = proomInformation;
}
Oh My.. you have a lot of errors...
1. boolean RunMeOnce = false; // '=' is assigning, '==' is comparing
This is not declared as static . So, you will need an object of type Bookings to call it.
Change your code in main() to
Bookings bk = new Bookings();
if (bk.RunMeOnce)
2. You dont need 2 Scanners to the same Stream (InputStream)
Scanner input = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
3. Show us your conferenceRoom and other classes for discovering more errors :)
You are not calling the constructor correctly. If the ConferenceRooms constructor you've provided is the only one you have, then it's clear why you're getting the error: provide the missing arguments!

pasword masking in console window and recursive function call in java

the following java code is executed in the console window in DR.java IDE.
i have the following two problems please help me friends.
Is it possible to make password masking ?? i tried a lot by googling but none worked for me (should use only console window for excecution).
When i call the "GetLoginDetails();" inside the "ShowAdminMainMenuFun(String EmpName)" method it is showing error ([line: 148] Error: Unhandled exception type java.io.IOException).
i thought of making recursive function but it dint worked can u correct the coding and post it back.
thanking u friends
{
import java.io.*;
import java.awt.*;
import java.io.Console;
import java.util.Scanner;
/*
UserLoginAuthentiction UserLoginAuthentictionObj = new UserLoginAuthentiction();
UserLoginAuthentictionObj.GetLoginDetails();
*/
class UserLoginAuthentiction
{
static String EmployeeID,Password;
public static byte resultRole = 0;
public static void main(String[] args) throws Exception
{
GetLoginDetails(); // it works well here but not works when called againin the following code
}
static void GetLoginDetails() throws IOException
{
Scanner sc = new Scanner(System.in);
byte resultRole = 0;
byte CountForLogin = 0;
System.out.println("Totally 3 attempts ");
do
{
if(CountForLogin<3){
System.out.print("\nEnter User Name:");
EmployeeID = sc.nextLine();
System.out.print("Enter Password :");
Password = sc.nextLine();
resultRole = ValidateUserIDAndPassword(EmployeeID,Password);
// if result is zero then the login is invalid,
// for admin it is one ,
// for quality analyser it is 2
// for project developer it is 3
// for developer it is 4
if(resultRole==0)
{
System.out.println("Username & Password does not match ");
System.out.print("Retry ::");
CountForLogin++;
if(CountForLogin>2)
{System.out.println("ur attempts are over is locked");}
}
else
{
System.out.println("here t should call the appropriate employe function");
GetRoleAndAssignFun(EmployeeID,resultRole);
break;
}
}
}while(resultRole==0);
}
static byte ValidateUserIDAndPassword(String EmployeeID,String Password)
{
byte resultRole = 0;
if((EmployeeID.equals("tcs"))&&(Password.equals("tcs")))
{
resultRole = 1;
}
/*
Code for checking the arraylist and returning the validations
this method should return the roles of the users password
*/
return resultRole;
}
static void GetRoleAndAssignFun(String EmpName ,int EmpRole)
{
// System.out.println(" ");
switch(EmpRole)
{
case 1:
System.out.println(" hi " +EmpName+ " u are logged in as admin ");
ShowAdminMainMenuFun(EmpName);
break;
case 2:
System.out.println(" hi " +EmpName+ " u are logged in as QA ");
// QualityAnalyserMainMenu(EmpName);
break;
case 3:
System.out.println(" hi " +EmpName+ " u are logged in as PM ");
// ProjectMAnagerMainMenu(EmpName);
break;
case 4:
System.out.println(" hi " +EmpName+ " u are logged in as DEVeloper ");
// DeveloperMainMenu(EmpName);
break;
default:
// System.out.println(EmpName +" You dont have any roles asigned ");
break;
}
}
public static void ShowAdminMainMenuFun(String EmpName)
{
Scanner sc = new Scanner(System.in);
int loop_option=0;
do
{
//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Hi "+ EmpName + " you can perform task ussing the menu given below");
System.out.println("press the appropriate option only");
System.out.println("1.Create New Employe Profile ");
System.out.println("2.See Employee's Profile ");
System.out.println("3. LogOut ");
System.out.println("Enter the Option u need:");
int option = sc.nextInt();
switch(option)
{
case 1:
System.out.println("1.Creating New Employe Profile");
//CreateNewEmployeeProfile();
break;
case 2:
System.out.println("2.See Employee's Profile ");
// ViewEmployeeProfile();
break;
case 3:
System.out.println("3. LogOut");
System.out.println("Do u want to continue logging out ?? If yes Press 1 ..");
boolean ConformLogout = false;
ConformLogout = sc.nextBoolean();
if(ConformLogout)
{
**GetLoginDetails();** //**** error is here */ how can i call this function please help me
}
else
{
}
// LogOut();
break;
default :
System.out.println(" You .. ");
}
System.out.println("Do u want to continue to main menu ?? Press 1 to continue..");
loop_option = sc.nextInt();
}while(loop_option==1);
}
}
}
Regarding your first question,
Is it possible to make password
masking?
You can use java.io.Console class to hide the password on console window.

Categories

Resources