Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task_1_4_1 #17

Merged
merged 14 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
.vscode
.vscode
.fake
9 changes: 9 additions & 0 deletions task_1_4_1/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

7 changes: 7 additions & 0 deletions task_1_4_1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build

bin
50 changes: 50 additions & 0 deletions task_1_4_1/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.4/userguide/building_java_projects.html in the Gradle documentation.
*/

plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id 'jacoco'
}

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// This dependency is used by the application.
implementation 'com.google.guava:guava:32.1.1-jre'
}

// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(20)
}
}

application {
// Define the main class for the application.
mainClass = 'task.StudentBook'
}

tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}

jacocoTestReport {
reports {
xml.required = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package task;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Excluding From Jacoco Test Report interface.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ExcludeFromJacocoGeneratedReport {
}
143 changes: 143 additions & 0 deletions task_1_4_1/app/src/main/java/task/Grade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package task;

/**
* Class represents subject grade in gradebook.
*/
public class Grade {

/**
* Name of subject.
*/
private String subject;

/**
* Grade for this subject.
*/
private int mark;

/**
* Boolean variable. True if mark is differentiated, false otherwise.
*/
private boolean differentiated;

/**
* Constructor of Grade class.
*
* @param subject name of the subject.
* @param mark grade for this subject.
* @param differentiated boolean variable. True if mark is differentiated, false otherwise.
* @throws GradeException special exception for GradeBook class. Contains information message.
*/
public Grade(String subject, int mark, boolean differentiated) throws GradeException {
this.subject = subject;
this.differentiated = differentiated;
this.setMark(mark);
}

/**
* Getter for mark.
*
* @return mark for subject.
*/
public int getMark() {
return mark;
}

/**
* Setter for mark.
*
* @param mark mark.
* @throws GradeException special exception for GradeBook class. Contains information message.
*/
public void setMark(int mark) throws GradeException {
if (mark < 2 || mark > 5) {
throw new GradeException("Mark must be between 2 and 5.\n");
}
if (differentiated) {
this.mark = mark;
} else {
this.mark = mark > 2 ? 5 : 2;
}
}

/**
* Getter for subject.
*
* @return name of the subject.
*/
public String getSubject() {
return subject;
}

/**
* Setter for subject.
*
* @param subject name of the subject.
*/
public void setSubject(String subject) {
this.subject = subject;
}

/**
* Getter for differentiated.
*
* @return true if mark is differentiated, false otherwise.
*/
public boolean isDifferentiated() {
return differentiated;
}

/**
* Setter for differentiated.
*
* @param differentiated boolean variable. True if mark is differentiated, false otherwise.
*/
public void setDifferentiated(boolean differentiated) {
this.differentiated = differentiated;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((subject == null) ? 0 : subject.hashCode());
result = prime * result + mark;
result = prime * result + (differentiated ? 1231 : 1237);
return result;
}

/**
* {@inheritDoc}
*/
@ExcludeFromJacocoGeneratedReport
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Grade other = (Grade) obj;
if (subject == null) {
if (other.subject != null) {
return false;
}
} else if (!subject.equals(other.subject)) {
return false;
}
if (mark != other.mark) {
return false;
}
if (differentiated != other.differentiated) {
return false;
}
return true;
}
}
Loading
Loading