//书本类
public class Book {
private int xuhao;
private String name;
private String zuozhe;
private String jianjie;
private String rujin;
public Book(int xuhao, String name, String zuozhe, String jianjie, String rujin) {
this.xuhao = xuhao;
this.name = name;
this.zuozhe = zuozhe;
this.jianjie = jianjie;
this.rujin = rujin;
}
public Book(){}
public int getXuhao() {
return xuhao;
}
public void setXuhao(int xuhao) {
this.xuhao = xuhao;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getZuozhe() {
return zuozhe;
}
public void setZuozhe(String zuozhe) {
this.zuozhe = zuozhe;
}
public String getJianjie() {
return jianjie;
}
public void setJianjie(String jianjie) {
this.jianjie = jianjie;
}
public String getRujin() {
return rujin;
}
public void setRujin(String rujin) {
this.rujin = rujin;
}
}
//用户类
public class User {
private String name;//登录名
private String pwd;//密码
public User(String name, String pwd) {
this.name = name;
this.pwd = pwd;
}
public User(){}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
//书本阅读流程类
package Sjlx.sjlx12;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
//书本阅读流程类
public class Read {
Scanner in = new Scanner(System.in);
ArrayList<User> userArrayList = new ArrayList<>();
ArrayList<Book> bookArrayList = new ArrayList<>();
ArrayList<Book> wuArrayList = new ArrayList<>();
public Read() {
}
//首页
public void Index() {
int xz = 0;
System.out.println("欢迎使用书虫阅读器");
System.out.println("========================");
System.out.println("1.登录");
System.out.println("2.注册");
System.out.println("3.退出");
System.out.println("========================");
System.out.println("请选择:");
xz = in.nextInt();
switch (xz) {
case 1:
Login();
break;
case 2:
zuce();
break;
case 3:
System.out.println("已退出应用 欢迎下次使用");
break;
}
}
//注册
public void zuce() {
User user = new User();
System.out.println("请输入登录名:");
user.setName(in.next());
System.out.println("请输入密码:");
user.setPwd(in.next());
System.out.println("请再次输入密码:");
String a;
a = in.next();
if (a.equals(user.getPwd())) {
for (int i = 0; i < userArrayList.size(); i++) {
if (user.getName().equalsIgnoreCase(userArrayList.get(i).getName())) {
System.out.println("用户已存在!");
zuce();
}
}
} else {
System.out.println("请重新输入");
zuce();
}
userArrayList.add(user);
System.out.println("注册成功快去登录吧!");
Login();
}
//验证有无有这个用户
public User hashUser(User user) {
if (user.getName() != null) {
for (int i = 0; i < userArrayList.size(); i++) {
if (userArrayList.get(i).getName().equalsIgnoreCase(user.getName()) && userArrayList.get(i).getPwd().equalsIgnoreCase(user.getPwd())) {
return userArrayList.get(i);
}
}
} else {
for (int i = 0; i < userArrayList.size(); i++) {
if (userArrayList.get(i).getName().equalsIgnoreCase(user.getName())) {
return userArrayList.get(i);
}
}
}
return null;
}
//登录
public boolean Login() {
User user = new User();
System.out.println("请输入您的登录名:");
user.setName(in.next());
System.out.println("请输入您的密码:");
user.setPwd(in.next());
if ((user = hashUser(user)) != null) {
System.out.println("登录成功!");
Book();
return true;
} else {
System.out.println("您的账号或密码输入错误!");
Index();
}
return false;
}
int yw;
//书本首页
public void Book() {
System.out.println("===========================");
System.out.println("0.退出登录");
System.out.println("1.言情");
System.out.println("2.武侠");
System.out.println("============================");
System.out.println("请选择:");
yw = in.nextInt();
switch (yw) {
case 0:
Index();
break;
case 1:
System.out.println("-----------------言情小说列表开始---------------------");
yanqing();
break;
case 2:
System.out.println("-----------------武侠小说列表开始---------------------");
yanqing();
break;
}
}
//言情类
FileReader fileReader;
File file;
ArrayList<String> arrayList = new ArrayList<>();
int a;
public void yanqing() {
System.out.println("序号 名称 作者 简介 点赞数 评论");
if (yw == 1) {
for (Book book : bookArrayList
) {
System.out.println(book.getXuhao() + "\t" + book.getName() + "\t" + book.getZuozhe() + "\t" + book.getJianjie()+"\t"+book.getDianzan()+"\t"+bookArrayList.get(0).getPinglun());
}
} else {
for (Book book : wuArrayList
) {
System.out.println(book.getXuhao() + "\t" + book.getName() + "\t" + book.getZuozhe() + "\t" + book.getJianjie()+"\t"+book.getPinglun());
}
}
System.out.println("-----------------------小说列表结束-------------------------------");
try {
dd();
} catch (IOException e) {
e.printStackTrace();
}
}
public void shangchuanxiaoshuo () {
Book book = new Book();
System.out.println("请输入小说名称:");
book.setName(in.next());
System.out.println("请输入作者:");
book.setZuozhe(in.next());
System.out.println("请输入简介:");
book.setJianjie(in.next());
do {
System.out.println("请输入上传的文件");
File file = new File(in.next());
if (file.isFile()) {
book.setRujin(file.getAbsolutePath());
break;
} else {
System.out.println("不存在这个文件!");
}
} while (true);
if(yw==1) {
book.setXuhao(bookArrayList.size() + 1);
bookArrayList.add(book);
}else {
book.setXuhao(wuArrayList.size() + 1);
wuArrayList.add(book);
}
}
/*
*
* 选择1
* */
public void dd() throws IOException {
System.out.println("0.返回上一级菜单");
System.out.println("-1.上传小说");
System.out.println("输入小说序列阅读:");
a = in.nextInt();
if (a == 0) {
Book();
} else if (a == -1) {
shangchuanxiaoshuo();
yanqing();
} else {
if (yw == 1) {
try {
file = new File(bookArrayList.get(a - 1).getRujin());
fileReader = new FileReader(file);
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
file = new File(wuArrayList.get(a - 1).getRujin());
fileReader = new FileReader(file);
} catch (Exception e) {
e.printStackTrace();
}
}
char[] array = new char[500];
int len = 0;
if (arrayList.size()==0){
while((len = fileReader.read(array)) >0) {
arrayList.add(new String(array, 0, len));
}
}
ye();
}
}
/*
*
* 选择2
* */int i=1;
public void ye() {
int aa = 0;
System.out.println(arrayList.get(aa));
do{
System.out.println("*********************************");
if(yw==1){
System.out.println("当前阅读:《" + bookArrayList.get(a - 1).getName() + "》第" + i + "/" + (arrayList.size() - 1) + "页");
}else {
System.out.println("当前阅读:《" + wuArrayList.get(a - 1).getName() + "》第" + i + "/" + (arrayList.size() - 1) + "页");
}System.out.println("*********************************");
System.out.println("0.返回上一级菜单");
System.out.println("1.下一页");
System.out.println("2.上一页");
int d = in.nextInt();
if (i >= (arrayList.size() - 1)) {
ckpl();
}
if (d == 0) {
yanqing();
} else if (d == 2) {
if (i == 1) {
System.out.println("这是第一页");
System.out.println("*********");
continue;
} else {
--a;
System.out.println(arrayList.get(aa));
}
} else if (d == 1){
++aa ;
i++;
System.out.println(arrayList.get(aa));
}while (true);
}
}
文章来源地址https://www.toymoban.com/news/detail-445100.html
文章来源:https://www.toymoban.com/news/detail-445100.html
到了这里,关于javaoop项目:书虫阅读器的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!