NEWS: Total Picture Views: 157232 | Total Article Views: 168311 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. PickUpThings with Becker Robot | 3. How to read a JSON and work with it | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

Method Class Example using Getter and Setter Java

Description:

In this example I will be showing how we use it.

Code:

/**** Launch.java *****/
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package runtime;

import connection.checkConnection;
import java.util.Scanner;
import profile.account;

/**
 *
 * @author Jean-Mathieu
 */
public class Launch {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        checkConnection checkC = new checkConnection();
        account a = new account();

        
        System.out.println("What is your username?");
        a.setUsername(input.nextLine());
        System.out.println("What is your password?");
        a.setPassword(input.nextLine());
        
        
        if(checkC.isConnected(a)){
            System.out.println("You're connected!");
        }else{
            System.out.println("Bad Login information.");
        }
    }
    
}
/**** account.java *****/
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package profile;

/**
 *
 * @author Jean-Mathieu
 */
public class account {
    private String username;
    private String password;
    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;
    }
    
}


/**** checkConnection.java *****/
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package connection;

import profile.account;

/**
 *
 * @author Jean-Mathieu
 */
public class checkConnection {
    public boolean isConnected(account a){
        if("Sheridan".equals(a.getUsername()) && "Sheridan".equals(a.getPassword())){
            return true;
        }else{
            return false;
        }
    }
}
Attachments:

Tags: Method Class Getter Setter Getter Setter

Total Views: 1435

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 12/05/14


affiliate_link

Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.