You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pairedProject/src/main/java/com/ybw/mathapp/service/StartController.java

166 lines
4.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.ybw.mathapp.service;
import com.ybw.mathapp.entity.User;
import java.io.IOException;
import java.util.List;
import java.util.Scanner;
public class StartController {
private double score;
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public void start() {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("=== 数学学习软件 ===");
System.out.println("1. 登录");
System.out.println("2. 注册");
System.out.print("请选择: ");
String choice = scanner.nextLine();
if ("1".equals(choice)) {
if (login()) {
showMainMenu(scanner);
}
} else if ("2".equals(choice)) {
if (register()) {
showMainMenu(scanner);
}
} else {
System.out.println("无效选择,请重新输入!");
}
}
}
private boolean login() {
System.out.println("\n=== 用户登录 ===");
Scanner scanner = new Scanner(System.in);
System.out.print("请输入邮箱: ");
String email = scanner.nextLine().trim();
System.out.print("请输入密码: ");
String password = scanner.nextLine();
// 这里应该调用真实的登录逻辑
System.out.println("登录功能待实现");
return true;
}
private boolean register() {
System.out.println("\n=== 用户注册 ===");
System.out.println("注册功能待实现");
return true;
}
private void showMainMenu(Scanner scanner) {
while (true) {
System.out.println("\n=== 主菜单 ===");
System.out.println("1. 开始练习");
System.out.println("2. 修改密码");
System.out.println("3. 退出登录");
System.out.print("请选择: ");
String choice = scanner.nextLine();
if ("1".equals(choice)) {
showLevelSelection(scanner);
} else if ("2".equals(choice)) {
changePassword(scanner);
} else if ("3".equals(choice)) {
System.out.println("退出登录成功!");
return;
} else {
System.out.println("无效选择,请重新输入!");
}
}
}
private void showLevelSelection(Scanner scanner) {
System.out.println("\n=== 选择题目级别 ===");
System.out.println("1. 小学");
System.out.println("2. 初中");
System.out.println("3. 高中");
System.out.println("4. 返回");
System.out.print("请选择: ");
String choice = scanner.nextLine();
String level = null;
switch (choice) {
case "1": level = "小学"; break;
case "2": level = "初中"; break;
case "3": level = "高中"; break;
case "4": return;
default:
System.out.println("无效选择!");
return;
}
showQuestionCount(scanner, level);
}
private void showQuestionCount(Scanner scanner, String level) {
System.out.println("\n=== 选择题目数量 ===");
System.out.print("请输入题目数量 (10-30): ");
try {
int count = Integer.parseInt(scanner.nextLine());
if (count < 10 || count > 30) {
System.out.println("题目数量必须在10-30之间");
return;
}
startQuiz(level, count);
} catch (NumberFormatException e) {
System.out.println("请输入有效的数字!");
}
}
private void startQuiz(String level, int count) {
System.out.println("\n开始 " + level + " 级别答题,共 " + count + " 题");
// 这里应该调用题目生成和答题逻辑
System.out.println("答题功能待实现");
// 模拟答题结果
this.score = 0.8; // 模拟80%的正确率
System.out.println("答题完成!得分: " + (score * 100) + "%");
}
private void changePassword(Scanner scanner) {
System.out.println("\n=== 修改密码 ===");
System.out.println("修改密码功能待实现");
}
public QuestionGenerator createGenerator(String level) {
switch (level) {
case "小学":
return new PrimarySchoolGenerator();
case "初中":
return new JuniorHighGenerator();
case "高中":
return new SeniorHighGenerator();
default:
return null;
}
}
public boolean isCorrectAnswer(String input, int correctAnswerIndex, List<Double> options) {
if (input.equals(String.valueOf(options.get(correctAnswerIndex)))) {
return true;
} else {
return false;
}
}
public double caculateScore(int rightCount, int totalCount) {
return rightCount / (double) totalCount;
}
}