Skip to content

Lab commit #25

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/projectSettingsUpdater.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions employees.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Employee{name='Employee0', email='[email protected]', age=25, salary=50000}
Employee{name='Employee1', email='[email protected]', age=26, salary=51000}
Employee{name='Employee2', email='[email protected]', age=0, salary=52000}
Employee{name='Employee3', email='[email protected]', age=28, salary=53000}
Employee{name='Employee4', email='[email protected]', age=29, salary=0}
Employee{name='Intern1', email='[email protected]', age=30, salary=12000}
Employee{name='Intern2', email='[email protected]', age=31, salary=20000}
Employee{name='Intern3', email='[email protected]', age=32, salary=17000}
Employee{name='Intern4', email='[email protected]', age=33, salary=58000}
Employee{name='Intern5', email='intern5example.com', age=34, salary=59000}
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>lab-java-standard-input-and-classes</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
64 changes: 64 additions & 0 deletions src/main/java/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
public class Employee {
private String name;
private String email;
private int age;
protected int salary;

public Employee(String name, String email, int age, int salary) {
setName(name);
setEmail(email);
setSalary(salary);
setAge(age);
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public int getAge() {
return age;
}

public void setAge(int age) {
if(age < 0){
this.age = 0;
}else{
this.age = age;
}

}

public int getSalary() {
return salary;
}

public void setSalary(int salary) {
if(salary < 0){
this.salary = 0;
}else{
this.salary = salary;
}
}

@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", email='" + email + '\'' +
", age=" + age +
", salary=" + salary +
'}' + "\n";
}
}
26 changes: 26 additions & 0 deletions src/main/java/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.sql.SQLOutput;

public class Intern extends Employee {

private final int MAX_SALARY = 20000;

public Intern(String name, String email, int age, int salary) {

super(name, email, age, salary);
if(salary > MAX_SALARY){
System.out.println("Intern salary cannot exceed " + MAX_SALARY);
this.salary = MAX_SALARY;
}
}

@Override
public void setSalary(int salary) {

if (salary > MAX_SALARY){
System.out.println("Intern salary cannot exceed " + MAX_SALARY);
this.salary = MAX_SALARY;
} else {
super.setSalary(salary);
}
}
}
26 changes: 26 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.io.FileWriter;
import java.io.IOException;

public class Main {
public static void main(String[] args) throws IOException {
try {
FileWriter writer = new FileWriter("employees.txt");

//generate 10 employees without for loop
writer.write(new Employee("Employee0", "[email protected]", 25, 50000).toString());
writer.write(new Employee("Employee1", "[email protected]", 26, 51000).toString());
writer.write(new Employee("Employee2", "[email protected]", -9, 52000).toString());
writer.write(new Employee("Employee3", "[email protected]", 28, 53000).toString());
writer.write(new Employee("Employee4", "[email protected]", 29, -100).toString());
writer.write(new Intern("Intern1", "[email protected]", 30, 12000).toString());
writer.write(new Intern("Intern2", "[email protected]", 31, 56000).toString());
writer.write(new Intern("Intern3", "[email protected]", 32, 17000).toString());
writer.write(new Employee("Intern4", "[email protected]", 33, 58000).toString());
writer.write(new Employee("Intern5", "intern5example.com", 34, 59000).toString());

writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Binary file added target/classes/Employee.class
Binary file not shown.
Binary file added target/classes/Intern.class
Binary file not shown.
Binary file added target/classes/Main.class
Binary file not shown.