其他分享
首页 > 其他分享> > 2019.08.19

2019.08.19

作者:互联网

2019.08.19
①完成音乐管理系统权限操作

package Music.ruanjian.service;

//import com.app.dao.UserDao;
import Music.ruanjian.bean.Music;
import Music.ruanjian.bean.User;
import Music.ruanjian.dao.MusicDao;
import Music.ruanjian.dao.UserDao;
import Music.ruanjian.util.DBUtil;
import com.sun.deploy.util.SyncAccess;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;

public class MusicService {
    public static void main(String[] args) throws SQLException {
        UserDao userdao = new UserDao();
        MusicService musicService = new MusicService();
        boolean flag = true;
        while (flag) {
            System.out.println("|-------------------------请输入用户名:-------------------------|");
            Scanner input = new Scanner(System.in);
            String username = input.next();
            System.out.println("|-------------------------请输入密码:---------------------------|");
            String password = input.next();
            System.out.println("|------------------------用户名:" + username + "  密码:" + password + "-----------------------|");
            System.out.println("|-------------------------请输入角色:---------------------------|");
            int type = input.nextInt();

            User user=userdao.login(username, password);
            if (user!=null) {
                musicService.getMenu(user);
            } else {
                musicService.register();
            }
        }
    }
            public void getMenu(User user) throws SQLException {
                MusicDao musicDao = new MusicDao();
                UserDao userDao=new UserDao();
                Scanner input = new Scanner(System.in);
                System.out.println("|---------------------------登录成功----------------------------|");
                System.out.println("|---------------------欢迎来到音乐管理系统----------------------|");
                System.out.println("|-------------\t1.音乐管理\t2.用户管理\t3.退出系统--------------|");
                int j = input.nextInt();
                if (j == 1) {
                    System.out.println("|---------------------欢迎进入音乐管理系统----------------------|");
                    System.out.println("|\t1.查询音乐\t2.添加音乐\t3.修改音乐\t4.删除音乐\t5.返回上一层|");
                    int a = input.nextInt();
                    switch (a) {
                        case 1:
                            List<Music> musics = musicDao.findAll();
                            System.out.println(musics);
                            System.out.println("|---------------------1.退出   0.返回上一级---------------------|");
                            int x = input.nextInt();
                            if (x==1) {
                                System.exit(0);
                            }else{
                                getMenu(user);
                            }
                            break;
                        case 2:
                            if(user.getType()!=0){
                                System.out.println("|---------------------你没有权限进行该操作!---------------------|");
                                System.out.println("|--------------------------返回上一级!-------------------------|");
                                getMenu(user);
                                break;
                            }
                            System.out.println("|--------------------请输入要添加歌曲的名称:--------------------|");
                            String n = input.next();
                            System.out.println("|--------------------请输入要添加歌曲的作者:--------------------|");
                            String au = input.next();
                            Music music = new Music();
                            music.setMusicname(n);
                            music.setAuthor(au);
                            musicDao.add(n, au);
                            System.out.println("|---------------------1.退出   0.返回上一级---------------------|");
                            int y = input.nextInt();
                            if (y==1) {
                                System.exit(0);
                            }else{
                                getMenu(user);
                            }
                            break;
                        case 3:
                            if (musicDao.modify()) {
                                System.out.println("|--------------------------修改成功!---------------------------|");
                            } else {
                                System.out.println("|--------------------------修改失败!---------------------------|");
                            }
                            System.out.println("|---------------------1.退出   0.返回上一级---------------------|");
                            int z = input.nextInt();
                            if (z==1) {
                                System.exit(0);
                            }else{
                                getMenu(user);
                            }
                            break;
                        case 4:
                            if(user.getType()!=0){
                                System.out.println("|---------------------你没有权限进行该操作!---------------------|");
                                System.out.println("|--------------------------返回上一级!-------------------------|");
                                getMenu(user);
                                break;
                            }
                            System.out.println("|---------------------请输入要删除歌曲的id:---------------------|");
                            int id = input.nextInt();
                            musicDao.delete(id);
                            System.out.println("|---------------------1.退出   0.返回上一级---------------------|");
                            int o = input.nextInt();
                            if (o==1) {
                                System.exit(0);
                            }else{
                                getMenu(user);
                            }
                            break;
                        case 5:
                            getMenu(user);
                            break;
                    }
                } else if (j == 2) {
                    System.out.println("|---------------------欢迎进入用户管理系统----------------------|");
                    System.out.println("|\t1.查询用户\t2.添加用户\t3.修改用户\t4.删除用户\t5.返回上一层|");
                    int a = input.nextInt();
                    switch (a){
                        case 1:
                            List<User> users=userDao.findAll();
                            System.out.println(users);
                            System.out.println("|---------------------1.退出   0.返回上一级---------------------|");
                            int x = input.nextInt();
                            if (x==1) {
                                System.exit(0);
                            }else{
                                getMenu(user);
                            }
                            break;
                        case 2:
                            System.out.println("|--------------------请输入要添加用户的id:--------------------|");
                            int id = input.nextInt();
                            System.out.println("|--------------------请输入要添加用户的密码:--------------------|");
                            String pa = input.next();
                            System.out.println("|--------------------请输入要添加用户的权限:--------------------|");
                            int ty = input.nextInt();
                            User user1 = new User();
                            user1.setId(id);
                            user1.setPassword(pa);
                            user1.setType(ty);
                            userDao.register(user1.getUsername(),user1.getPassword(),user1.getType());
                            System.out.println("|---------------------1.退出   0.返回上一级---------------------|");
                            int y = input.nextInt();
                            if (y==1) {
                                System.exit(0);
                            }else{
                                getMenu(user);
                            }
                            break;
                        case 3:
                            System.out.println("|---------------------请输入要修改用户的id:---------------------|");
                            int id1=input.nextInt();
                            System.out.println("|--------------------请输入要修改用户的密码:--------------------|");
                            String password=input.next();
                            userDao.modify(id1,password);
                            System.out.println("|---------------------1.退出   0.返回上一级---------------------|");
                            int z = input.nextInt();
                            if (z==1) {
                                System.exit(0);
                            }else{
                                getMenu(user);
                            }
                            break;
                        case 4:
                            System.out.println("|---------------------请输入要删除用户的id:---------------------|");
                            int id2 = input.nextInt();
                            userDao.delete(id2);
                            System.out.println("|---------------------1.退出   0.返回上一级---------------------|");
                            int o = input.nextInt();
                            if (o==1) {
                                System.exit(0);
                            }else{
                                getMenu(user);
                            }
                            break;
                        case 5:
                            getMenu(user);
                            break;

                    }
                }
            }
            public void register() throws SQLException {
                UserDao userDao=new UserDao();
                Scanner input=new Scanner(System.in);
                System.out.println("|---------------------------登录失败----------------------------|");
                System.out.println("|---------------------------请先注册----------------------------|");
                System.out.println("|-------------------------请输入用户名:-------------------------|");
                String username1 = input.next();
                System.out.println("|--------------------------请输入密码:--------------------------|");
                String password1 = input.next();
                System.out.println("|--------------------------请确认密码:--------------------------|");
                String password2 = input.next();
                System.out.println("|--------------------------请输入角色:--------------------------|");
                int play1 = input.nextInt();
                if (password1.equals(password2) && (play1==0 || play1==1)) {
                    userDao.register(username1, password1,play1);
                    System.out.println("|-----------------------是否登入或退出Y/N-----------------------|");
                    String i = input.next();
                    if (i.equals("N")) {
                        System.exit(0);
                    } else if (!i.equals("Y")) {
                        System.out.println("|---------------------------输入错误!--------------------------|");
                        System.exit(0);
                    }else{
                        User user2=new User();
                        user2.setUsername(password1);
                        user2.setPassword(password2);
                        user2.setType(play1);

                    }
                } else {
                    System.out.println("|---------------------密码有误!请重新注册!----------------------|");
                }
            }
        }

②用递归实现n!

package Finance.ruanjian.service;

import java.util.Scanner;

public class test {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入n:");
            long n = Long.parseLong(sc.nextLine());
            System.out.println(n+"!="+getFac(n));
        }

        public static long getFac(long n){
            if(n == 1){
                return 1;
            }
            return getFac(n-1)  * n;
        }
    }

③编写个人项目

标签:2019.08,19,System,nextInt,int,println,input,out
来源: https://blog.csdn.net/weixin_44809978/article/details/99825103