Welcome Guest.   Make a donation to an author on the site October 26, 2014, 02:03:29 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2014! Download dozens of custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Plz help me in writing Java equivalent code for this problem!  (Read 1620 times)
simsim00
Participant
*
Posts: 2

View Profile Give some DonationCredits to this forum member
« on: June 13, 2009, 10:20:40 AM »

This is my C++ code for the problem given below. But since i'm newbie to java, dont know how to write equivalent Java code. If you people can help, plz do so. Helping hands are always praised worthy. Im stuck...Plz assist me..

Code for Login page in C++
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <fstream>
using std::ifstream;
#include <string>
using std::string;
string readString(ifstream&);
int main(int argc, char *argv[])
{
char user[80];
char pass[80];
string line_in;
string::size_type pos;
ifstream fp_in;
int count = 0;
string user_pass[100][2];
fp_in.open("users.txt");
if(fp_in == NULL)
{
cout << "Could not open user file, exiting." << endl;
return -1;
}
while(!fp_in.eof())
{
line_in=readString(fp_in);
if(line_in.length() > 0)
{
pos = line_in.find("\t",0);
if( pos != string::npos)
{
user_pass[count][0] = line_in.substr(0,pos);
user_pass[count][1] = line_in.substr(pos+1);
count++;
}
}
}
fp_in.close();
if(!count > 0)
{
cout << "Userlist is empty, exiting" << endl;
return -2;
}
int logged_in=0;
while(!logged_in)
{
cout << "Enter user name: ";
cin >> user;
cout << "Enter password: ";
cin >> pass;
int found = 0;
for(int x=0;x<count && !found;x++)
{
if(user_pass
  • .compare(user) == 0)
{
found = 1;
if(user_pass
  • [1].compare(pass) == 0)
{
found = 1;
logged_in = 1;
}
else
{
cout << "Invalid password!" << endl;
}
}
}
if(!found)
{
cout << "Invalid username!" << endl;
}
}
cout << "Logged in successfully!" << endl;
return 0;
}
string readString(ifstream& reader)
{
char buffer[256];
reader.getline(buffer,256);
string str1 = buffer;
return str1;
}

Problem:
Writing a maintainable code makes the product with High Quality. Here you are given a scenario where you have to write a maintainable code for the given problem.

Scenario:


Virtual Solutions is an IT solution provider company. It has hired you as a Software Engineer. Your job is to write code, but at the same it should be of High Quality. Your Team Lead has asked you to write a very small code of user login functionality. The code should be of High Quality.

You are required to

a. Write correct code for the user login in Java following the guidelines for writing code
b. Make use of Hungarian Notation for coding purpose

c. Make use of Comments in the Code where required necessary.
« Last Edit: June 13, 2009, 10:41:58 AM by simsim00 » Logged
javafreak
Participant
*
Posts: 2


View Profile Give some DonationCredits to this forum member
« Reply #1 on: September 21, 2009, 07:24:27 AM »

   import java.util.*;
   import java.io.*;
   public class login
   {
   public static void main(String ar[])
   {   
   try
   {
     BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
   String s;Integer pass;
   System.out.println("enter the Username");
   s=input.readLine();
   System.out.println("enter the password must be numeric");
   pass=Integer.parseInt(input.readLine());
   if(s.equals("sam") && pass.equals(123) )
   {
   System.out.println("you are logined sucess fully");
   }
   else
   {
   System.out.println("you have entered the wrong");
   }
   }
      catch (Exception e) {
        e.printStackTrace();
      }
   }
   }
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.03s | Server load: 0.13 ]