Skip to content

Week2 lab (Viktoriia Zaiets) #21

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
29 changes: 29 additions & 0 deletions Week2 lab/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions Week2 lab/.idea/.gitignore

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

6 changes: 6 additions & 0 deletions Week2 lab/.idea/misc.xml

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

8 changes: 8 additions & 0 deletions Week2 lab/.idea/modules.xml

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

4 changes: 4 additions & 0 deletions Week2 lab/.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 Week2 lab/employees.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 Michael Robinson [email protected] 31 30000.0
2 Francis Smith [email protected] 45 50000.0
3 Amanda Minter [email protected] 23 19000.0
4 Elaine Porter [email protected] 35 46000.0
5 Leroy Bowen [email protected] 65 55000.0
6 Landen Hurley [email protected] 25 50000.0
7 Marisol Wu [email protected] 37 46000.0
8 Kyng Barrett [email protected] 24 35000.0 Needs attention, this intern has a higher salary than expected.
9 Oaklyn Ramirez [email protected] 20 18000.0
10 Jessica Armstrong [email protected] 41 50000.0
19 changes: 19 additions & 0 deletions Week2 lab/src/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Employee {
public String name;
public String email;
public int age;
public double salary;

public Employee(String name, String email, int age, double salary) {
this.name = name;
this.email = email;
this.age = age;
this.salary = salary;
}

public String toString() {
return name + " " + email + " " + age + " " + salary;
}

}

9 changes: 9 additions & 0 deletions Week2 lab/src/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Intern extends Employee {

public Intern(String name, String email, int age, double salary) {
super(name, email, age, salary);
if (salary >= 20000){
salary = 20000;
}
}
}
40 changes: 40 additions & 0 deletions Week2 lab/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.FileWriter;
import java.io.IOException;

public class Main {


public static void main(String[] args) throws IOException {
Employee employee1 = new Employee("Michael Robinson", "[email protected]", 31, 30000);
Employee employee2 = new Employee("Francis Smith", "[email protected]", 45, 50000);
Intern employee3 = new Intern("Amanda Minter", "[email protected]", 23, 19000);
Employee employee4 = new Employee("Elaine Porter", "[email protected]", 35, 46000);
Employee employee5 = new Employee("Leroy Bowen", "[email protected]", 65, 55000);
Employee employee6 = new Employee("Landen Hurley", "[email protected]", 25, 50000);
Employee employee7 = new Employee("Marisol Wu", "[email protected]", 37, 46000);
Intern employee8 = new Intern("Kyng Barrett", "[email protected]", 24, 35000);
Intern employee9 = new Intern("Oaklyn Ramirez", "[email protected]", 20, 18000);
Employee employee10 = new Employee("Jessica Armstrong", "[email protected]", 41, 50000);

Employee[] employees = {employee1, employee2, employee3, employee4, employee5, employee6, employee7, employee8, employee9, employee10};

try {
FileWriter writer = new FileWriter("employees.txt", false);
for(int i = 0; i < employees.length; i++) {
int employeeNum = i + 1;
if (employees[i] instanceof Intern && employees[i].salary >= 20000){
writer.write(employeeNum + " " + employees[i].toString() + " !Needs attention, this intern has a higher salary than expected!\n");
} else {
writer.write(employeeNum + " " + employees[i].toString()+ '\n');
}
}

writer.close();

System.out.println("Data has been appended to the file.");
} catch (IOException e) {
e.printStackTrace();
}

}
}