package fhq0626;
import java.util.Scanner;
import java.util.Random;
public class User {
String username;
String password;
int age;
String address;
String phone;
int score;
boolean isonline;
public void showinfo(){
System.out.println("-------个人信息-------");
System.out.println("用户名:"+username);
System.out.println("密码:"+password);
System.out.println("年龄:"+age);
System.out.println("地址:"+address);
System.out.println("手机:"+phone);
System.out.println("积分:"+score);
System.out.println("在线标识:"+isonline);
System.out.println("--------------------");
}
public boolean checkpassword(String pwdin){
if(pwdin.equals(password)){
System.out.println(username+"密码验证通过");
return true;
}
else{
System.out.println(username+"密码验证失败");
return false;
}
}
public boolean login(String pwdin){
System.out.println("正在登陆中。。。");
if(checkpassword(pwdin)){
if(isonline){
System.out.println("用户已经在线");
return false;
}
else{isonline=true;
score+=5;
System.out.println(username+"登陆成功");
return true;}}
else{
System.out.println(username+"登陆失败");
return false;
}
}
public void logout(){
System.out.println("正在退出中。。。");
if(isonline){
isonline=false;
System.out.println(username+"退出成功");
}
else{
System.out.println(username+"不在线,一经退出");
}
}
public void choujiang(int credit){
if (credit>score||credit<0||credit==0){
System.out.println("请输入大于零小于等于总积分的积分数");
}
else {
score -= credit;
Random r=new Random();
int b=3*credit;
int number=r.nextInt(b);
score+=number;
System.out.println("抽奖后积分为"+score);
}
}
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
User user1=new User();
System.out.println("请输入用户名:");
user1.username=sc.nextLine();
System.out.println ("请输入密码:");
user1.password = sc.nextLine ();
System.out.println ("请输入年龄:");
user1.age = Integer.parseInt (sc.nextLine ());
System.out.println ("请输入地址:");
user1.address = sc.nextLine ();
System.out.println ("请输入手机号:");
user1.phone = sc.nextLine ();
System.out.println ("请输入积分:");
user1.score = Integer.parseInt (sc.nextLine ());
System.out.println (user1.username + "用户初始属性数据输入完成");
System.out.println ("--------------------------");
while (true){
System.out.println("请选择功能:1.查看信息2.登录3.退出4.积分抽奖");
String choice=sc.nextLine();
if(choice.equals ("1")){
user1.showinfo();
} else if(choice.equals ("2")){
System.out.println ("请输入密码:");
String pwdIn = sc.nextLine ();
user1.login (pwdIn);// 登录
} else if(choice.equals ("3")){
user1.logout ();}// 退出}
else if(choice.equals ("4")){
if(user1.isonline)
{System.out.println("您的积分是"+user1.score);
System.out.println("请输入参与抽奖的积分");
int a= Integer.parseInt (sc.nextLine ());
user1.choujiang (a);}
else{ System.out.println("请先登录");}
}
else{
System.out.println ("输入错误,请重新输入 对应操作的数字 1 2 3");
}
}}}
一个有查看信息,验证密码,登录,登出,修改信息,积分抽奖的用户登陆系统
最新推荐文章于 2024-08-25 22:29:30 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)