-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuizAttempt.java
More file actions
43 lines (36 loc) · 1.22 KB
/
Copy pathQuizAttempt.java
File metadata and controls
43 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.time.LocalDateTime;
/**
* Represents a single quiz attempt by a player
*/
public class QuizAttempt {
private LocalDateTime timestamp;
private String category;
private int score;
private int correctAnswers;
private int totalQuestions;
private int timeTaken;
public QuizAttempt(String category, int score, int correctAnswers,
int totalQuestions, int timeTaken) {
this.timestamp = LocalDateTime.now();
this.category = category;
this.score = score;
this.correctAnswers = correctAnswers;
this.totalQuestions = totalQuestions;
this.timeTaken = timeTaken;
}
public LocalDateTime getTimestamp() { return timestamp; }
public String getCategory() { return category; }
public int getScore() { return score; }
public int getCorrectAnswers() { return correctAnswers; }
public int getTotalQuestions() { return totalQuestions; }
public int getTimeTaken() { return timeTaken; }
public double getAccuracy() {
return totalQuestions > 0 ? (double) correctAnswers / totalQuestions * 100 : 0;
}
@Override
public String toString() {
return String.format("[%s] %s - Score: %d (%d/%d) - Time: %ds",
timestamp.toLocalDate(), category, score,
correctAnswers, totalQuestions, timeTaken);
}
}