Java nt(); } else if(角色相等(“HOD”)){ System.out.println(“每堂课1份报告:学生与评估类型”); reportChoice=s.nextInt(); } else if(角色相等(“COD”)) { System.o
nt(); } else if(角色相等(“HOD”)){ System.out.println(“每堂课1份报告:学生与评估类型”); reportChoice=s.nextInt(); } else if(角色相等(“COD”)) { System.out.println(“1)每份学生报告:科目与评估类型”); System.out.println(“2)所有学生报告:学生与评估类型”); System.out.println(“每堂课3份报告:学生与评估类型”); System.out.println(“4)每个科目报告:学生与评估类型”); reportChoice=s.nextInt(); } 其他的 { System.out.println(“错误”); } //相应的函数调用 if(reportChoice==1){ if(角色相等(“ST”)) perSubject(); else if(角色相等(“CT”)) perStudent(); else if(角色相等(“HOD”)) perClass(); else if(角色相等(“COD”)) perStudent(); } else if(reportChoice==2){ if(角色相等(“CT”)) 所有学生(); else if(角色相等(“COD”)) 所有学生(); } else if(reportChoice==3){ if(角色相等(“COD”)) perClass(); } else if(reportChoice==4){ if(角色相等(“COD”)) perSubject(); } 否则{ System.out.println(“错误”); 登录(); } } 捕获(例外e) { 系统输出打印ln(e); } } 公共静态布尔checkRole(){ //检查其是否为有效角色 尝试 { while(rs.next()){ if(Role.equals(rs.getString(1))) 温度=真; } } 捕获(例外e) { 系统输出打印ln(e); } 最后 { 返回温度; } } 公共静态void perSubject(){ 试一试{ System.out.println(“生成每个主题的报告…”); System.out.println(“所选主题:“+主题”); rs=stmt.executeQuery(“选择学生+科目+数据.Name,”+Subject+”.UT1,“+Subject+”.UT2,“+Subject+”.PRJ,“+Subject+”.TE,“+Subject+”。最后从“+Subject+”内部连接学生+数据“+Subject+”。滚动编号=学生+数据。滚动编号和学生+数据。Class=“+Grade+”和学生+数据。节=“+Section+”,按学生数据。名称分组); WriteToFile.Write(reportChoice,Role);//错误如下 } 捕获(例外e) { 系统输出打印ln(e); } } 公共静态无效人员(){ System.out.println(“生成每个学生的报告…”); System.out.println(“学生选择:+学生选择”); } 公共静态void perClass(){ 系统输出打印项次(“每类”); } 公共静态void allStudent(){ 系统输出打印项次(“所有螺柱”); } } 导入java.io.BufferedWriter; 导入java.io.FileWriter; 导入java.io.IOException; 导入java.sql.*; 公共类WriteToFile扩展了MarkEntry{ 公共静态最终字符串FILENAME=“Report.html”; 公共静态BufferedWriter bw=null; 公共静态FileWriter fw=null; 公共静态无效写入(int n,字符串角色){ 试一试{ fw=新文件编写器(文件名); bw=新的缓冲写入程序(fw); 如果(n==1&&role.equals(“ST”)){ 写下(“报告1:科目教师报告表,th,td{边框:1px纯黑;}科目:“+Subject+”班级:“+Grade+”部分:“+Section+”名称UT1 UT2 PRJ TE Final”); while(rs.next()){ bw.写(“”); write(“+rs.getString(1)+”); 写(“+rs.getInt(2)+”); 写(“+rs.getInt(3)+”); 写(“+rs.getInt(4)+”); 写(“+rs.getInt(5)+”); 写(“+rs.getInt(6)+”); bw.写(“”); } //分别获取平均值和STDEV并通过html显示 rs=stmt.executeQuery(“选择平均值(“+Subject+”.UT1)、平均值(“+Subject+”.UT2)、平均值(“+Subject+”.PRJ)、平均值(“+Subject+”.TE)、平均值(“+Subject+”.Final)和“+Subject+”;”; bw.写入(“平均值”); while(rs.next()){ 写(“+rs.getInt(1)+”); 写(“+rs.getInt(2)+”); 写(“+rs.getInt(3)+”); 写(“+rs.getInt(4)+”); 写(“+rs.getInt(5)+”); } bw.写(“”); rs=stmt.executeQuery(“选择STDDEV(“+Subject+”.UT1)、STDDEV(“+Subject+”.UT2)、STDDEV(“+Subject+”.PRJ)、STDDEV(“+Subject+”.TE)、STDDEV(“+Subject+”.Final)从“+Subject+”); bw.写入(“标准偏差”); while(rs.next()){ 写(“+rs.getInt(1)+”); 写(“+rs.getInt(2)+”); 写(“+rs.getInt(3)+”); 写(“+rs.getInt(4)+”); 写(“+rs.getInt(5)+”); } bw.写(“”); bw.写(“”); 系统输出打印项次(“完成”); } else如果(n==1&&Role.equals(“CT”)){ bw.写(“每名学生选择:”+学生选择); bw.书面(“主题UT1 UT2 PRJ TE最终版”); //为单独的主题显示标记 //从sql获取数据 //主题方面: //英式 写(“英语>”); rs=stmt.executeQuery(“选择UT1、UT2、PRJ、TE、最终英语,其中Roll_No=“+studentRollNo”); while(rs.next()){ 写(“+rs.getInt(1)+”); 写(“+rs.getInt(2)+”); 写(“+rs.getInt(3)+”); 写(“+rs.getInt(4)+”); 写(“+rs.getInt(5)+”); }Java nt(); } else if(角色相等(“HOD”)){ System.out.println(“每堂课1份报告:学生与评估类型”); reportChoice=s.nextInt(); } else if(角色相等(“COD”)) { System.o,java,class,object,inheritance,Java,Class,Object,Inheritance,nt(); } else if(角色相等(“HOD”)){ System.out.println(“每堂课1份报告:学生与评估类型”); reportChoice=s.nextInt(); } else if(角色相等(“COD”)) { System.out.println(“1)每份学生报告:科目与评估类型”); System.out.println(“2)所有学生报告:学生与评估类型”); System.out.println(“每堂课3份报告:学生与评估类型”); System.out.
import java.util.*;
import java.sql.*;
public class MarkEntry {
public static Connection con;
public static Statement stmt;
public static ResultSet rs;
public static String Username;
public static String Password;
public static String Role;
public static String Name;
public static String Grade;
public static String Section;
public static String Subject;
public static boolean temp = false;
public static int reportChoice;
public static String studentChoice;
public static int studentRollNo;
public static Scanner s = new Scanner(System.in);
public static void main(String args[]){
//Connextion
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/harssha_gowtham","root","");
stmt=con.createStatement();
Login();
// ResultSet rs=stmt.executeQuery("select * from student_data");
// while(rs.next())
// System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3) + " " + rs.getString(4));
// con.close();
}catch(Exception e)
{
System.out.println(e);
}
}
public static void Login(){
//Lagin
try {
System.out.println("Welcome to the Mark Entry System ");
System.out.println("Username: ");
Username = s.nextLine();
System.out.println("Password: ");
Password = s.nextLine();
//Fetching the name with the user name.
rs = stmt.executeQuery("select Name from teachers_login where Username = '" + Username + "'" + "AND Password = '" + Password +"'");
if(rs.next()){
Name = rs.getString(1);
}
else{
//Incorrect Login
System.out.println("Incorrect Username or Password");
Login();
}
rs.beforeFirst(); //reinitializing result set after looping through the table
System.out.println();
//Displaying all possible roles with class and section and letting user choose one
System.out.println("Possible Roles:");
System.out.println();
System.out.println("Role Grade Section");
rs = stmt.executeQuery("select Role, Class, Section from teachers_roles WHERE Name= '" + Name +"'");
while(rs.next()){
System.out.println(rs.getString(1) + " " + rs.getInt(2) + " " + rs.getString(3)) ;
}
//Asking for a role
System.out.println("Login As?");
Role = s.nextLine();
rs.beforeFirst();
if((Role.equals("ST") || Role.equals("HOD")) && ((checkRole() == true))){
//Ask for the class and the section as there can be many
System.out.print("Grade: ");
Grade = s.nextLine();
System.out.println();
System.out.print("Section:");
Section = s.nextLine();
//Have to insert checkGrade()
//Get subject Automatically
rs = stmt.executeQuery("SELECT Subject FROM teachers_roles WHERE teachers_roles.Class = '" + Grade + "' AND teachers_roles.Section = '" + Section +"' AND teachers_roles.Name = '" + Name +"'");
if(rs.next())
Subject = rs.getString(1);
}
else if(Role.equals("CT") && ((checkRole() == true)))
{
//Ask for the class and the section as there can be many
rs = stmt.executeQuery("SELECT class , Section from teachers_roles WHERE Name = '" + Name + "' AND Role = '" + Role + "'");
while(rs.next()){
Grade = rs.getString(1);
Section = rs.getString(2);
}
//Debug info
System.out.println(Grade);
System.out.println(Section);
System.out.println("Choose the Student:");
studentChoice = s.nextLine();
rs = stmt.executeQuery("select student_data.Roll_No FROM student_data WHERE student_data.Name ='"+studentChoice+"'");
studentRollNo = rs.getInt(1);
perStudent();
}
else if(Role.equals("COD") && ((checkRole() == true)))
{
//There is nothing for a COD
}
else
{
System.out.println("Error.");
Login();
}
//Plug in incorrect role code when done
//Asking for the type of Report
System.out.println("Choose Reports");
if(Role.equals("ST")){
System.out.println("1) Per Subject Report : Students Vs. Assesment Types ");
reportChoice = s.nextInt();
}
else if(Role.equals("CT")){
System.out.println("1) Per Student Report : Subject Vs. Assesment Types ");
System.out.println("2) All Student Report : Students Vs. Assesment Types ");
reportChoice = s.nextInt();
}
else if(Role.equals("HOD")){
System.out.println("1) Per Class Report : Students Vs. Assessment Types ");
reportChoice = s.nextInt();
}
else if(Role.equals("COD"))
{
System.out.println("1) Per Student Report : Subject Vs. Assesment Types ");
System.out.println("2) All Student Report : Students Vs. Assesment Types ");
System.out.println("3) Per Class Report : Students Vs. Assessment Types ");
System.out.println("4) Per Subject Report : Students Vs. Assesment Types ");
reportChoice = s.nextInt();
}
else
{
System.out.println("Error");
}
//Corresponding function calls
if(reportChoice == 1 ) {
if(Role.equals("ST"))
perSubject();
else if(Role.equals("CT"))
perStudent();
else if(Role.equals("HOD"))
perClass();
else if(Role.equals("COD"))
perStudent();
}
else if(reportChoice == 2){
if(Role.equals("CT"))
allStudent();
else if(Role.equals("COD"))
allStudent();
}
else if(reportChoice == 3){
if(Role.equals("COD"))
perClass();
}
else if(reportChoice == 4){
if(Role.equals("COD"))
perSubject();
}
else {
System.out.println("Error.");
Login();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public static boolean checkRole() {
//To check if its a valid role or not
try
{
while(rs.next()){
if(Role.equals(rs.getString(1)))
temp = true;
}
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
return temp;
}
}
public static void perSubject() {
try{
System.out.println("Generating Per Subject report...");
System.out.println("Subject Chosen: " + Subject);
rs = stmt.executeQuery("SELECT student_data.Name , "+Subject+".UT1 , "+Subject+".UT2 , "+Subject+".PRJ , "+Subject+".TE ,"+Subject+".Final FROM "+Subject+" INNER JOIN student_data ON "+Subject+".Roll_No = student_data.Roll_No AND student_data.Class ="+Grade+" AND student_data.Section = '"+Section+"' GROUP BY student_data.Name");
WriteToFile.Write(reportChoice,Role); //Here is the error
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void perStudent() {
System.out.println("Generating Per Student Report...");
System.out.println("Student Chosen:" + studentChoice);
}
public static void perClass() {
System.out.println("Per Class");
}
public static void allStudent() {
System.out.println("all stud");
}
}
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.*;
public class WriteToFile extends MarkEntry {
public static final String FILENAME = "Report.html";
public static BufferedWriter bw = null;
public static FileWriter fw = null;
public static void Write(int n, String role) {
try {
fw = new FileWriter(FILENAME);
bw = new BufferedWriter(fw);
if(n==1 && role.equals("ST")){
bw.write("<!DOCTYPE html><HTML> <HEAD> <meta charset=\"utf-8\"/> Report 1: Subject Teacher Report </HEAD> <style> table, th, td { border: 1px solid black; }</style> <h1 > Subject: " + Subject+ " </h1> <h2 > Class:"+Grade+ " Section:"+ Section+" </h2> <BODY> <table style=width:50%> <tr> <th>Name</th> <th>UT1</th> <th>UT2</th> <th>PRJ</th> <th>TE</th> <th>Final</th> </tr>");
while(rs.next()){
bw.write("<tr>");
bw.write("<td>"+rs.getString(1)+"</td>");
bw.write("<td>"+rs.getInt(2)+"</td>");
bw.write("<td>"+rs.getInt(3)+"</td>");
bw.write("<td>"+rs.getInt(4)+"</td>");
bw.write("<td>"+rs.getInt(5)+"</td>");
bw.write("<td>"+rs.getInt(6)+"</td>");
bw.write("</tr>");
}
//Getting average and Stddev seperately and displaying it through html
rs = stmt.executeQuery("select AVG("+Subject+".UT1) , AVG("+Subject+".UT2) , AVG("+Subject+".PRJ) , AVG("+Subject+".TE) , AVG("+Subject+".Final) from "+Subject+";");
bw.write(" <tr><td> <b>Average</b> </td>");
while(rs.next()){
bw.write("<td><b>"+rs.getInt(1)+"</b></td>");
bw.write("<td><b>"+rs.getInt(2)+"</b></td>");
bw.write("<td><b>"+rs.getInt(3)+"</b></td>");
bw.write("<td><b>"+rs.getInt(4)+"</b></td>");
bw.write("<td><b>"+rs.getInt(5)+"</b></td>");
}
bw.write("</tr>");
rs = stmt.executeQuery("select STDDEV("+Subject+".UT1),STDDEV("+Subject+".UT2),STDDEV("+Subject+".PRJ),STDDEV("+Subject+".TE),STDDEV("+Subject+".Final) from "+Subject+" ");
bw.write("<tr><td> <b>Standard Deviation</b> </td>");
while(rs.next()){
bw.write("<td><b>"+rs.getInt(1)+"</b></td>");
bw.write("<td><b>"+rs.getInt(2)+"</b></td>");
bw.write("<td><b>"+rs.getInt(3)+"</b></td>");
bw.write("<td><b>"+rs.getInt(4)+"</b></td>");
bw.write("<td><b>"+rs.getInt(5)+"</b></td>");
}
bw.write("</tr>");
bw.write("</table> </BODY> </HTML>");
System.out.println("Done");
}
else if(n==1&& Role.equals("CT")){
bw.write("<!DOCTYPE html><html><head><title>Per Student</title><meta charset=\"utf\"/></head><body> Student Chosen:"+studentChoice);
bw.write("<table style=width:50%> <tr> <th>Subject</th> <th>UT1</th> <th>UT2</th> <th>PRJ</th> <th>TE</th> <th>Final</th> </tr>");
//displaying marks for inividual subjects
//fetching data from sql
//Subject Wise:
//English
bw.write("<tr> <td><b>English></b></td>");
rs=stmt.executeQuery("select UT1 , UT2, PRJ, TE, Final from english where Roll_No ="+studentRollNo);
while(rs.next()){
bw.write("<td><b>"+rs.getInt(1)+"</b></td>");
bw.write("<td><b>"+rs.getInt(2)+"</b></td>");
bw.write("<td><b>"+rs.getInt(3)+"</b></td>");
bw.write("<td><b>"+rs.getInt(4)+"</b></td>");
bw.write("<td><b>"+rs.getInt(5)+"</b></td>");
}
bw.write("/tr");
bw.write("</body></html>");
}
} catch (IOException e) {
e.printStackTrace();
}
catch (SQLException e){
System.out.println(e);
}
finally {
try {
if (bw != null)
bw.close();
if (fw != null)
fw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}