Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskinneavy committed Sep 11, 2019
0 parents commit 357724c
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
bin/
target/
log/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties


# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
*.jar
!lib/**/sbccutils-1.1.jar
!/.mvn/wrapper/maven-wrapper.jar

# Eclipse - Just in case
.classpath
.project
.settings/
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch)-Program<A04 - Employee>",
"request": "launch",
"mainClass": "edu.sbcc.cs105.Program",
"console": "integratedTerminal",
"stopOnEntry": false

}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
147 changes: 147 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# A04 - Employee

# Overview

You will want to complete enough of L02 - PhoneBill lab to understand how to create classes, attributes, and methods before completing the UML portion of this lab. You can do the code portion first, though.

The project name of this exercise is **Employee**.

The purpose of this assignment is to give you some practice problem solving, writing your own classes, and running unit tests.

# Problem Description

Implement a class **Employee** and test it in your **Program****.java**. An employee has a name (a String) and a salary (a double). Your Employee class must follow the provided specification below:

**A constructor with two explicit arguments:**

`public Employee(String employeeName, double currentSalary)` - Constructor. The constructor will initialize instance variables of the same name as provided parameters. That is, it will assign the values from the parameters to the instance variables.

**Method Declarations / Class Interface**

`**public String getName()` - Returns the name of the employee from the instance variable **employeeName**

`public double getSalary()` - Returns the current salary. It gets this value from an instance variable named **currentSalary**

`public void raiseSalary(double byPercent)` - Gives the employee a raise according to the explicit argument **byPercent**. This method will modify the value of the **currentSalary** instance variable

**Sample Usage (paste this inside your main() method of Program.Java):**

```java
Employee harry = new Employee("Harry", 10000);
harry.raiseSalary(10); // Harry gets a 10% raise.
double harrysSalary = harry.getSalary();
```

# Getting Started

We are going to do this exercise by writing the object that solves the problem first (in a source file called **Employee.java**) and then testing it using code we write into **Program.java**. Using the techniques shown on the web page titled "How to Start Every Project in this Class" create a source file called **Employee.java** as well as a file called **Program.java**.

Open up the **Employee.java** file and replace the code with the code contained in the box below:

```java
/**
* CS 105 Theory and Practice I
* CRN: [CHANGE THIS TO YOUR INFORMATION]
* Assignment: Employee
*
* Statement of code ownership: I hereby state that I have written all of this
* code and I have not copied this code from any other person or source.
*
* @author [CHANGE THIS TO YOUR INFORMATION]
*/
package edu.sbcc.cs105;

/**
* This class implements an emplyee which is a person with a name and a salary.
*
*/
public class Employee {

/**
* Constructor that creates a new Employee with an initial name and salary.
*
*/
public Employee(String employeeName, double currentSalary) {
// TODO: Initialize instance variables from constructor (ctor) parameters
}

// Accessors that are obvious and have no side effects don't have to have
// any documentation unless you are creating a library to be used by other
// people.
public String getName() {
// TODO: Return the name of the employee;
}

public double getSalary() {
// TODO: Return the current salary of the employee
}

/**
* Raise the salary by the amount specified by the explicit argument.
*
*/
public void raiseSalary(double byPercent) {
// TODO: Calculate the new salary by increasing it by the percent passed in as a method argument
}
}
```

You'll notice that there is only a skelton of code. It current doesn't do anything. You will have to add instance variables and code to get this class defined properly. Read the comments (and the problem) to understand what the problem is and how you will solve it.

Don't forget to through the code and replace every instance of **[CHANGE THIS TO YOUR INFORMATION]** to the appropriate item. Be sure that the square brackets are included when you replace the text.

Next, using the same technique you used to create the **Employee.java** file to create another file called **Program.java**. This is where your test code will go. Replace the code in that file with the code in the grey box below:

```java
/**
* CS 105 Theory and Practice I
* CRN: [CHANGE THIS TO YOUR INFORMATION]
* Assignment: Employee
*
* Statement of code ownership: I hereby state that I have written all of this
* code and I have not copied this code from any other person or source.
*
* @author [CHANGE THIS TO YOUR INFORMATION]
*/
package edu.sbcc.cs105;

/**
* This class provides first level testing the Employee object.
*
*/
public class Program {

/**
* Create an employee and test that the proper name has been created. Test
* the initial salary amount and then give the employee a raise. Then check
* to make sure the salary matches the raised salary.
*
*
* @param args
* command line values. Not used in this example.
*/
public static void main(String[] args) {
// TODO: Paste code in here from the sample usage section. Feel free to adjust things like the salary and percent raised
}
}
```

Similar to the **Employee.java** file go through **Program.java** and change the **[CHANGE THIS TO YOUR INFORMATION]** text to the proper items. There are two items to be changed.

You will also notice that **Program.java** does not contain any code to test the **Employee.java** source code. Write some test routines based upon the problem description. There are a couple of lines of code you can use at a starting point.

Once you've written your code run the code by single clicking on **Program.java** in the package explorer and selecting **Run->Run** from the menu or using the keyboard shortcut. Examine the output. Does it do what you want? If not, how can you modify the code to do what you want?

## Running Unit Tests

Don't forget to run unit tests. The unit test is called TestEmployee.java

**YOUR UNIT TESTS MUST PASS BEFORE SUBMITTING THE FILE OR YOU GET NOTHING (Reference to the original Charlie and the Chocolate Factory).**

## Create UML Diagram for the Project

Similar to the , you will create a UML diagram for this project and include it in the project submission. The UML assignment package should be named A04 - Employee and the exported XMI file should be named the same as the Java project. If we used our fictional student, Inigo Montoya, the file would be named Montoya-In-Employee.xmi

## Submitting Your Assignment

Follow the standard instructions for submitting a Java assignment: [How to Submit Assignments](https://canvas.sbcc.edu/courses/25771/pages/how-to-submit-assignments-new?module_item_id=761292)
19 changes: 19 additions & 0 deletions buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 0.2

phases:
install:
commands:
- echo Nothing to do in the install phase...
pre_build:
commands:
- echo Nothing to do in the pre_build phase...
build:
commands:
- echo Build started on `date`
- mvn install
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- target/project.jar
Binary file added lib/sbccutils-1.1.jar
Binary file not shown.
61 changes: 61 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.sbcc.cs105</groupId>
<artifactId>A04-Employee</artifactId>
<name>A04 - Employee</name>
<version>1.0</version>
<packaging>jar</packaging>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.10</version>
</dependency>
<dependency>
<groupId>com.github.ngeor</groupId>
<artifactId>checkstyle-rules</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<configuration>
<configLocation>com/github/ngeor/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<dependencies>
<dependency>
<!--
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.2.0</version>
<scope>test</scope>
-->
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>

</project>
10 changes: 10 additions & 0 deletions src/main/java/edu/sbcc/cs105/Program.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Replace all code in this file with what is provided in the assignment
package edu.sbcc.cs105;

public class Program {

public static void main(String[] args) {
System.out.println("Someday, I'll be a real program!");
}

}
65 changes: 65 additions & 0 deletions src/test/java/unittest/cs105/TestEmployee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package unittest.cs105;

import static java.lang.System.*;
import static org.junit.Assert.*;

import org.junit.*;

import edu.sbcc.cs105.*;

public class TestEmployee {
private static final int maximumScore = 10;
private static final int maximumAssignmentScore = 15;
private static int totalScore;

@BeforeClass
public static void beforeTesting() {
totalScore = 0;
}

@AfterClass
public static void afterTesting() {
out.printf("Your program's functionality scores %d out of %d.\n\n", totalScore, maximumScore);

int difference = maximumAssignmentScore - maximumScore;
String correctedPoint = (difference == 1) ? "point" : "points";

out.printf("The assignment is worth a total of %d where the remainder of %d %s\n", maximumAssignmentScore,
difference, correctedPoint);
out.println("comes from grading related to documentation, algorithms, and other");
out.println("criteria.");
}

@Test
public void checkName() throws Exception {
Employee e = new Employee("Jose Martinez", 10000);

assertEquals("Name must match name given in constructor.", "Jose Martinez", e.getName());

totalScore += 2;
}

@Test
public void checkSalary() throws Exception {
Employee e = new Employee("Jose Martinez", 10000);

assertEquals("Name must match name given in constructor.", 10000, e.getSalary(), 0.01);

totalScore += 2;
}

@Test
public void checkRaise() throws Exception {
Employee e = new Employee("Jose Martinez", 10000);

assertEquals("Name must match name given in constructor.", 10000, e.getSalary(), 0.01);
totalScore += 2;

e.raiseSalary(17);

assertEquals("Salary not raised appropriately.", 11700, e.getSalary(), 0.01);

totalScore += 4;
}

}

0 comments on commit 357724c

Please sign in to comment.