first commit
This commit is contained in:
89
SE1011 Lab Results/1011barnestrL2.htm
Normal file
89
SE1011 Lab Results/1011barnestrL2.htm
Normal file
@@ -0,0 +1,89 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"/><title>barnestr</title></head><body><xmp>
|
||||
# Lab 2 -- Small Programs
|
||||
|
||||
* Date: 9-13-2017
|
||||
* Course: SE1011
|
||||
* Submitted to: Dr. Chris Taylor
|
||||
|
||||
>> | Earned | Possible | Criteria |
|
||||
>> | ------ | -------- | ------------------------------------------------ |
|
||||
>> | 100 | 100 | All tests passed |
|
||||
>
|
||||
> # Feedback
|
||||
> * Nice work
|
||||
|
||||
# Negative
|
||||
Given a number, return its negative.
|
||||
|
||||
```
|
||||
public int negate(int value) {
|
||||
int number = -(value);
|
||||
return number;
|
||||
}
|
||||
```
|
||||
|
||||
> #### Suggested simplification
|
||||
> This could simplified even more. You could just say:
|
||||
>
|
||||
> ```
|
||||
return -value;
|
||||
```
|
||||
>
|
||||
> In this case, it doesn't matter too much, but as our program become
|
||||
> more complicated, being able to write things in as simple a way as possible
|
||||
> will allow you to write more complicated programs without adding unneeded
|
||||
> complications.
|
||||
|
||||
# How Many Pennies
|
||||
Given a number representing dollars and cents, e.g. 2.18, return the number of pennies corresponding to that amount.
|
||||
|
||||
```
|
||||
public int howManyPennies(double dollars) {
|
||||
double pennies = (dollars * 100);
|
||||
return (int)pennies;
|
||||
}
|
||||
```
|
||||
|
||||
# Last Half
|
||||
Given a non-empty string with an even number of characters, return the last half. E.g., Given "this" return "is".
|
||||
|
||||
```
|
||||
String lastHalf(String str) {
|
||||
int length;
|
||||
int pos;
|
||||
length = str.length();
|
||||
pos = length / 2;
|
||||
String res;
|
||||
res = str.substring(pos);
|
||||
return res;
|
||||
}
|
||||
```
|
||||
|
||||
# Make Initialization
|
||||
Make a program that writes a line of Java code. Given the name of the variable and its value, return an initialization of an int with that name and value. E.g., given the name "x" and the value "5", return "int x = 5;"
|
||||
|
||||
```
|
||||
String makeInitialization(String name, int value) {
|
||||
return ("int " + name + " = " + value + ";");
|
||||
}
|
||||
```
|
||||
|
||||
# Fractions
|
||||
Given a fraction expressed as a numerator and denominator, return the fraction as a floating point number.
|
||||
|
||||
```
|
||||
public double fraction(int numerator, int denominator) {
|
||||
double result;
|
||||
result = (double)numerator / denominator;
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
> #### Pick good identifier names
|
||||
> Picking good identifier names will become more important as your
|
||||
> programs get more complicated. Picking good names can be difficult.
|
||||
> I'd like you to start getting practice with that now, even though
|
||||
> it really isn't necessary to understand these simple programs.
|
||||
|
||||
|
||||
</xmp><script type="text/javascript" src="http://msoe.us/taylor/gradedown.js"></script></body></html>
|
||||
319
SE1011 Lab Results/1011barnestrL3 (003).htm
Normal file
319
SE1011 Lab Results/1011barnestrL3 (003).htm
Normal file
@@ -0,0 +1,319 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"/><title>barnestr</title></head><body><xmp>
|
||||
# Lab 3 -- Conditionals
|
||||
|
||||
* Date: 9-27-2017
|
||||
* Course: SE1011-051
|
||||
* Submitted to: Dr. Chris Taylor
|
||||
|
||||
>> | Earned | Possible | Criteria |
|
||||
>> | ------ | -------- | ------------------------------------------------ |
|
||||
>> | 5 | 5 | In lab demonstration |
|
||||
>> | 70 | 70 | Technical quality (see comments below) |
|
||||
>> | 12 | 15 | Passed tests (see comments below) |
|
||||
>> | 5 | 5 | Following submission instructions |
|
||||
>> | 5 | 5 | Internal documentation/program clarity (see comments below) |
|
||||
>
|
||||
> # Feedback
|
||||
> * Nice work
|
||||
|
||||
# Lab3GUI.java
|
||||
|
||||
```
|
||||
import javax.swing.*;
|
||||
```
|
||||
> #### -1 Did not use the required package
|
||||
> Your classes were supposed to be in a package named the same as your
|
||||
> MSOE login (`barnestr`).
|
||||
|
||||
```
|
||||
/*
|
||||
* Course: SE1011-051
|
||||
* Term: Fall 2017-2018
|
||||
```
|
||||
> #### Please put this at the very beginning
|
||||
> You should put this comment at the very beginning of your file.
|
||||
|
||||
```
|
||||
* Assignment Lab 3 GUI
|
||||
* Author: Trevor Barnes
|
||||
* Date: 9/19/17
|
||||
*/
|
||||
|
||||
//S Filer Bracket Differences Multiplied by Tax Rate
|
||||
//.10*9325 = 932.5
|
||||
//.15*28625 = 4293.75
|
||||
//.25*53950 = 13487.5
|
||||
//.28*99750 = 27930
|
||||
```
|
||||
> #### Have program calculate these
|
||||
> You should have the program calculate these rather than having
|
||||
> this as a comment. If these calculations were shown in the code
|
||||
> (and you had meaningful names), you wouldnt need this comment
|
||||
> because the reader of your code could see what the numbers mean
|
||||
> and how they were calculated.
|
||||
|
||||
```
|
||||
//.33*225050 = 74266.5
|
||||
//.35*1700 = 595
|
||||
//J Filer Bracket Differences Multiplied by Tax Rate
|
||||
//.10*18650 = 1865.0
|
||||
//.15*57250 = 8575.5
|
||||
//.25*77200 = 19300.0
|
||||
//.28*80250 = 22470.0
|
||||
//.33*183350 = 60505.5
|
||||
//.35*54000 = 18900.0
|
||||
|
||||
public class Lab3GUI {
|
||||
public static void main(String[] args) {
|
||||
Double sb1 = 932.5;
|
||||
Double sb2 = 4293.75;
|
||||
Double sb3 = 13487.5;
|
||||
```
|
||||
> #### -1 Pick meaningful identifier names
|
||||
> You should pick meaningful identifier names. This makes it easier
|
||||
> to understand your code. It can also reduce the amount of comments you
|
||||
> need to include because your code will be more self-explanatory.
|
||||
|
||||
```
|
||||
Double sb4 = 27930.0;
|
||||
Double sb5 = 74266.5;
|
||||
Double sb6 = 595.0;
|
||||
|
||||
Double jb1 = 1865.0;
|
||||
Double jb2 = 8575.5;
|
||||
Double jb3 = 19300.0;
|
||||
Double jb4 = 22470.0;
|
||||
Double jb5 = 60505.5;
|
||||
Double jb6 = 18900.0;
|
||||
String filer = JOptionPane.showInputDialog
|
||||
(null, "Are you a single filer or a married joint filer (enter 's' or 'j')");
|
||||
Double income = new Double (JOptionPane.showInputDialog
|
||||
(null, "Enter an estimate of your earned income for 2017"));
|
||||
if(filer.equals ("s")) {
|
||||
if(income <= 9325) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + income*.10);
|
||||
}
|
||||
else if (income >= 9326 && income <= 37950 ) {
|
||||
```
|
||||
> #### Avoid magic numbers
|
||||
> The [Coding Standard](http://msoe.us/taylor/se1011/CodingStandard) requires
|
||||
> the following:
|
||||
>> Named constants are used instead of numeric literals.
|
||||
>
|
||||
> You should avoid having seemingly random values sprinkled throughout your
|
||||
> code. These values are often referred to as **magic numbers** because
|
||||
> they appear magically. One great way to avoid this is to create named
|
||||
> constants in your code. By providing a name you can describe what the
|
||||
> value represents. For example:
|
||||
>
|
||||
> ```
|
||||
final int SINGLE_15_THRESHOLD = 37950;
|
||||
```
|
||||
>
|
||||
> This creates a variable, `SINGLE_15_THRESHOLD`, and assigns it a value that cannot
|
||||
> change. Instead of tossing `37950` later in your code.
|
||||
|
||||
```
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-9325)*.15)+(sb1)));
|
||||
}
|
||||
else if (income >= 37951 && income <= 91900 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-37950)*.25)+(sb1)+(sb2)));
|
||||
}
|
||||
else if (income >= 91901 && income <= 191650 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-91900)*.28)+(sb1)+(sb2)+(sb3)));
|
||||
}
|
||||
else if (income >= 191651 && income <= 416700 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-191650)*.33)+(sb1)+(sb2)+(sb3)+(sb4)));
|
||||
}
|
||||
else if (income >= 416701 && income <= 418400 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-416700)*.35)+(sb1)+(sb2)+(sb3)+(sb4)+(sb5)));
|
||||
}
|
||||
else if (income >= 418401 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-418400)*.396)+(sb1)+(sb2)+(sb3)+(sb4)+(sb5)+(sb6)));
|
||||
}
|
||||
}
|
||||
else if(filer.equals ("j")) {
|
||||
if(income <= 18650) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + income*.10);
|
||||
}
|
||||
else if (income >= 18651 && income <= 75900 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-18650)*.15)+(jb1)));
|
||||
}
|
||||
else if (income >= 75901 && income <= 153100 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-75900)*.25)+(jb1)+(jb2)));
|
||||
}
|
||||
else if (income >= 153101 && income <= 233350 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-153100)*.28)+(jb1)+(jb2)+(jb3)));
|
||||
}
|
||||
else if (income >= 233351 && income <= 416700 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-233350)*.33)+(jb1)+(jb2)+(jb3)+(jb4)));
|
||||
}
|
||||
else if (income >= 416701 && income <= 470700 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-416700)*.35)+(jb1)+(jb2)+(jb3)+(jb4)+(jb5)));
|
||||
}
|
||||
else if (income >= 470701 ) {
|
||||
JOptionPane.showMessageDialog
|
||||
(null, "Your estimated taxes for 2017 are: $" + (((income-470700)*.396)+(jb1)+(jb2)+(jb3)+(jb4)+(jb5)+(jb6)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# Lab3Console
|
||||
|
||||
```
|
||||
import java.util.Scanner;
|
||||
/*
|
||||
* Course: SE1011-051
|
||||
* Term: Fall 2017-2018
|
||||
* Assignment Lab 3 Console
|
||||
* Author: Trevor Barnes
|
||||
* Date: 9/19/17
|
||||
*/
|
||||
|
||||
//S Filer Bracket Differences Multiplied by Tax Rate
|
||||
//.10*9325 = 932.5
|
||||
//.15*28625 = 4293.75
|
||||
//.25*53950 = 13487.5
|
||||
//.28*99750 = 27930
|
||||
//.33*225050 = 74266.5
|
||||
//.35*1700 = 595
|
||||
//J Filer Bracket Differences Multiplied by Tax Rate
|
||||
//.10*18650 = 1865.0
|
||||
//.15*57250 = 8575.5
|
||||
//.25*77200 = 19300.0
|
||||
//.28*80250 = 22470.0
|
||||
//.33*183350 = 60505.5
|
||||
//.35*54000 = 18900.0
|
||||
|
||||
public class Lab3Console {
|
||||
public static void main(String[] args) {
|
||||
Double sb1 = 932.5;
|
||||
Double sb2 = 4293.75;
|
||||
Double sb3 = 13487.5;
|
||||
Double sb4 = 27930.0;
|
||||
Double sb5 = 74266.5;
|
||||
Double sb6 = 595.0;
|
||||
|
||||
Double jb1 = 1865.0;
|
||||
Double jb2 = 8575.5;
|
||||
Double jb3 = 19300.0;
|
||||
Double jb4 = 22470.0;
|
||||
Double jb5 = 60505.5;
|
||||
Double jb6 = 18900.0;
|
||||
System.out.println("Are you a single filer or married joint filer? (enter 's' or 'j'):");
|
||||
Scanner sl = new Scanner(System.in);
|
||||
String filer = sl.nextLine();
|
||||
|
||||
System.out.println("Enter an estimate of you earned income for 2017:");
|
||||
Double income = Double.valueOf(sl.next());
|
||||
if(filer.equals ("s")) {
|
||||
if (income <= 9325) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + income * .10);
|
||||
}
|
||||
else if (income >= 9326 && income <= 37950) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income - 9325) * .15) + (sb1)));
|
||||
}
|
||||
```
|
||||
> #### -1 No result for $37950.34
|
||||
> Careful here. If the user enters an estimated income between ranges, your
|
||||
> program will not calculate the tax owed. For example, if the user is a
|
||||
> single filer with an estimated income of $37950.34, that will be between
|
||||
> $37950 and $37951. As a result, every `if` conditional
|
||||
> will be `false` and no calculation will occur.
|
||||
|
||||
```
|
||||
else if (income >= 37951 && income <= 91900) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income - 37950) * .25) + (sb1) + (sb2)));
|
||||
}
|
||||
else if (income >= 91901 && income <= 191650) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income - 91900) * .28) + (sb1) + (sb2) + (sb3)));
|
||||
}
|
||||
else if (income >= 191651 && income <= 416700) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income - 191650) * .33) + (sb1) + (sb2) + (sb3) + (sb4)));
|
||||
}
|
||||
else if (income >= 416701 && income <= 418400) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income - 416700) * .35) + (sb1) + (sb2) + (sb3) + (sb4) + (sb5)));
|
||||
}
|
||||
else if (income >= 418401) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income - 418400) * .396) + (sb1) + (sb2) + (sb3) + (sb4) + (sb5) + (sb6)));
|
||||
}
|
||||
}
|
||||
else if(filer.equals ("j")) {
|
||||
if(income <= 18650) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + income*.10);
|
||||
}
|
||||
else if (income >= 18651 && income <= 75900 ) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income-18650)*.15)+(jb1)));
|
||||
}
|
||||
else if (income >= 75901 && income <= 153100 ) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income-75900)*.25)+(jb1)+(jb2)));
|
||||
}
|
||||
else if (income >= 153101 && income <= 233350 ) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income-153100)*.28)+(jb1)+(jb2)+(jb3)));
|
||||
}
|
||||
```
|
||||
> #### Do not Repeat Yourself
|
||||
> One principle in software development is DRY - __D__on't __R__epeat __Y__ourself.
|
||||
> Having nearly identical code in mulitple place means increases the amount
|
||||
> of code you need to write and makes it harder to maintain. It is harder
|
||||
> to maintain because, if you decide to change something in the repeated
|
||||
> code, you have to change it everywhere.
|
||||
>
|
||||
> A very common mistake is to miss a few places that need to be updated
|
||||
> making the program behave slightly differently depending on which version
|
||||
> of the code is encountered.
|
||||
>
|
||||
> In this particular case, you could just have one output statement
|
||||
> at the end of all the calculations. Inside each `if`/`else` block
|
||||
> you could calculate the amount of tax due, and then just print it
|
||||
> once at the end.
|
||||
|
||||
```
|
||||
else if (income >= 233351 && income <= 416700 ) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income-233350)*.33)+(jb1)+(jb2)+(jb3)+(jb4)));
|
||||
}
|
||||
else if (income >= 416701 && income <= 470700 ) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income-416700)*.35)+(jb1)+(jb2)+(jb3)+(jb4)+(jb5)));
|
||||
}
|
||||
else if (income >= 470701 ) {
|
||||
System.out.println("Your estimated taxes for 2017 are: $" + (((income-470700)*.396)+(jb1)+(jb2)+(jb3)+(jb4)+(jb5)+(jb6)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# Instructor Tests
|
||||
|
||||
> #### Incorrect calculation for a joint filer earning $100000
|
||||
> For a joint filer earning $100000 total tax should be $16477.50 but you calculated a tax burden of $16465.50.
|
||||
|
||||
> #### Incorrect calculation for a joint filer earning $200000
|
||||
> For a joint filer earning $200000 total tax should be $42884.50 but you calculated a tax burden of $42872.50.
|
||||
|
||||
> #### Incorrect calculation for a joint filer earning $300000
|
||||
> For a joint filer earning $300000 total tax should be $74217.00 but you calculated a tax burden of $74205.00.
|
||||
|
||||
> #### Incorrect calculation for a joint filer earning $450000
|
||||
> For a joint filer earning $450000 total tax should be $124383.00 but you calculated a tax burden of $124371.00.
|
||||
|
||||
> #### Incorrect calculation for a joint filer earning $500000
|
||||
> For a joint filer earning $500000 total tax should be $143230.80 but you calculated a tax burden of $143218.80.
|
||||
|
||||
|
||||
</xmp><script type="text/javascript" src="http://msoe.us/taylor/gradedown.js"></script></body></html>
|
||||
116
SE1011 Lab Results/1011barnestrL4.htm
Normal file
116
SE1011 Lab Results/1011barnestrL4.htm
Normal file
@@ -0,0 +1,116 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"/><title>barnestr</title></head><body><xmp>
|
||||
# Lab 4 -- Loops
|
||||
|
||||
* Date: 10-2-2017
|
||||
* Course: SE1011-051
|
||||
* Submitted to: Dr. Chris Taylor
|
||||
|
||||
>> | Earned | Possible | Criteria |
|
||||
>> | ------ | -------- | ------------------------------------------------ |
|
||||
>> | 5 | 5 | Demo by end of lab |
|
||||
>> | 85 | 85 | Met requirements / Technical quality |
|
||||
>> | 5 | 5 | Coding standard compliance and program clarity |
|
||||
>> | 5 | 5 | Following submission instructions |
|
||||
>
|
||||
> # Feedback
|
||||
> * Nice work
|
||||
|
||||
# Lab4.java
|
||||
|
||||
```
|
||||
/*
|
||||
* Course: SE1011-051
|
||||
* Term: Fall 2017-2018
|
||||
* Assignment Lab 3 Console
|
||||
```
|
||||
> #### This is lab 4
|
||||
|
||||
```
|
||||
* Author: Trevor Barnes
|
||||
* Date: 9/26/17
|
||||
*/
|
||||
|
||||
/*
|
||||
This program is a game where a user chooses between two scenarios where their uncle offers them money.
|
||||
Until he dies (0-40 weeks) he will either add an original value of money between $0-5000 per week or
|
||||
double money every week starting at $0.01.
|
||||
If the option chosen is greater than the opposite option, the user wins and the user is shown how much extra money they made.
|
||||
If the option chosen is less than the opposite option, the user loses and the user is shown how much money they missed out on.
|
||||
Finally, the user is given the option to play again or end the program.
|
||||
*/
|
||||
|
||||
package barnestr;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Lab4 {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int again = 1;
|
||||
while(again == 1) {
|
||||
```
|
||||
> #### Prefer to use a `boolean` here
|
||||
> Since this is supposed to keep track of one of two things (whether to
|
||||
> repeat or not), you should use a `boolean` variable to store the value.
|
||||
|
||||
```
|
||||
|
||||
System.out.println("Suppose you have a wealthy uncle who gives you two options for your inheritance. He will add to your inheritance every week until he dies according to one of two schemes:\n" +
|
||||
"\n" +
|
||||
"1. Starting with a given amount (such as $5000), he will add that amount to your total inheritance every week, or\n" +
|
||||
"2. Starting with one penny, he will double your inheritance every week.\n" +
|
||||
"Option 2 will always outpace option 1 at some point in the future, but the question is when will option 2 be a better financial decision for you than option 1 and will it happen before your uncle dies?\n" +
|
||||
"\n" +
|
||||
"Enter which option you would prefer ('1' or '2'):");
|
||||
int option=sc.nextInt();
|
||||
double number1 = Math.random();
|
||||
double startAmount = 5000*number1;
|
||||
double startAmountA = 5000*number1;
|
||||
```
|
||||
> #### Pick meaningful identifier names
|
||||
> You should pick meaningful identifier names. This makes it easier
|
||||
> to understand your code. It can also reduce the amount of comments you
|
||||
> need to include because your code will be more self-explanatory.
|
||||
>
|
||||
> `startAmount` does not contain the starting amount when looping.
|
||||
|
||||
```
|
||||
double exp = .01;
|
||||
double number2 = Math.random();
|
||||
int randWeeks = (int) (40*number2);
|
||||
int week = 1;
|
||||
while (week < randWeeks) {
|
||||
System.out.format("Week %2d Linear: $%.2f, Exponential: $%.2f\n", week, startAmount, exp);
|
||||
```
|
||||
> #### -5 Stop weekly display after exponential exceeds linear
|
||||
> You should not display the weekly totals once the exponential total
|
||||
> exceeds the linear total.
|
||||
|
||||
```
|
||||
week = week + 1;
|
||||
startAmount = (startAmount + startAmountA);
|
||||
exp = exp*2;
|
||||
}
|
||||
|
||||
System.out.println("\n" + "Your uncle dies after " + week + " weeks so you");
|
||||
if(option == 1 && startAmount > exp) {
|
||||
double finalAmount = startAmount - exp;
|
||||
System.out.format("got lucky and ended up with an extra $%.2f\n", finalAmount);
|
||||
} else if(option == 1 && startAmount < exp) {
|
||||
double finalAmount = exp - startAmount;
|
||||
System.out.format("got unlucky and missed out on $%.2f\n", finalAmount);
|
||||
} else if(option == 2 && exp > startAmount) {
|
||||
double finalAmount = exp - startAmount;
|
||||
System.out.format("got lucky and ended up with $%.2f\n", finalAmount);
|
||||
} else if(option == 2 && exp < startAmount) {
|
||||
double finalAmount = startAmount - exp;
|
||||
System.out.format("got unlucky and missed out on $%.2f\n", finalAmount);
|
||||
}
|
||||
System.out.println("Do you want to play again? (1 for yes) or (0 for no)");
|
||||
again = sc.nextInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</xmp><script type="text/javascript" src="http://msoe.us/taylor/gradedown.js"></script></body></html>
|
||||
108
SE1011 Lab Results/1011barnestrL5.htm
Normal file
108
SE1011 Lab Results/1011barnestrL5.htm
Normal file
@@ -0,0 +1,108 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"/><title>barnestr</title></head><body><xmp>
|
||||
# Lab 5 - Library Classes
|
||||
|
||||
* Date: 10-9-2017
|
||||
* Course: SE1011-051
|
||||
* Submitted to: Dr. Chris Taylor
|
||||
|
||||
>> | Earned | Possible | Criteria |
|
||||
>> | ------ | -------- | ------------------------------------------------ |
|
||||
>> | 85 | 85 | Met requirements / Technical quality |
|
||||
>> | 10 | 10 | Coding standard compliance and program clarity |
|
||||
>> | 5 | 5 | Following submission instructions |
|
||||
>
|
||||
> # Feedback
|
||||
> * Nice work
|
||||
|
||||
# Lab5.java
|
||||
|
||||
```
|
||||
/*
|
||||
* Course: SE1011-051
|
||||
* Term: Fall 2017-2018
|
||||
* Assignment: Lab 5
|
||||
* Author: Trevor Barnes
|
||||
* Date: 10/3/17
|
||||
*/
|
||||
package barnestr;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Lab5 {
|
||||
public static void main(String[] args) {
|
||||
boolean error = false;
|
||||
Scanner in = new Scanner(System.in);
|
||||
String again = "y";
|
||||
while (again.equals("y") || again.equals("Y")) {
|
||||
```
|
||||
> #### Considering using the do/while
|
||||
> Since you essentially need to ask the user for input at least once,
|
||||
> you should consider using a `do`/`while` loop. That would allow you
|
||||
> to avoid having to duplicate the user input code.
|
||||
|
||||
```
|
||||
//Ask user for point amount
|
||||
System.out.println("Enter the preferred number of randomly generated points:");
|
||||
//Generate points
|
||||
int pointAmt = in.nextInt();
|
||||
in.nextLine();
|
||||
while (pointAmt <= 0) {
|
||||
System.out.println("Enter the preferred number of randomly generated points:");
|
||||
pointAmt = in.nextInt();
|
||||
}
|
||||
in.nextLine();
|
||||
```
|
||||
> #### Should be inside the loop
|
||||
> This `in.nextLine();` call should be inside the loop so that
|
||||
> it only runs if there was a call to `in.nextInt()`. Having it
|
||||
> here requires the user to hit enter one too many times.
|
||||
|
||||
```
|
||||
int inside = 0;
|
||||
double finalPoint = 0;
|
||||
for (int i = 0; i < pointAmt; i++) {
|
||||
double pointX = Math.random();
|
||||
double pointY = Math.random();
|
||||
```
|
||||
> #### -2 Did not use `Random` class
|
||||
> The lab assignment required that you write a program that:
|
||||
>> * Generates the desired number of random points using the `Random` class.
|
||||
>
|
||||
> Your program does not make use of the `Random` class.
|
||||
|
||||
```
|
||||
//Calculate the hypotenuse of the two points
|
||||
double pointC = Math.sqrt(Math.pow(pointX, 2) + Math.pow(pointY, 2));
|
||||
//Determine whether the point is inside or outside of the circle (pointC <= pi/4)
|
||||
if (pointC <= 1) {
|
||||
inside++;
|
||||
//Convert proportion to pi
|
||||
}
|
||||
finalPoint = (double) inside / (double) pointAmt;
|
||||
}
|
||||
System.out.println((finalPoint * 4));
|
||||
```
|
||||
> #### -4 Does not display correct number of digits
|
||||
> The lab assignment required that for each estimate the program:
|
||||
>> * Displays the estimated value and the __number of correct digits__.
|
||||
|
||||
```
|
||||
do {
|
||||
System.out.println("Would you like to generate a new estimate for pi?");
|
||||
again = in.nextLine();
|
||||
} while (!again.equals("y") && !again.equals("Y") && !again.equals("n") && !again.equals("N"));
|
||||
}
|
||||
```
|
||||
> #### -4 Does not display best estimate
|
||||
> The lab assignment required that for each estimate the program:
|
||||
>> * If the user enters `n` or `N`, the program should __display the best estimate of pi__ generated while the program ran and then exit.
|
||||
|
||||
```
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> #### -10 Late penalty
|
||||
> Your submission was 1 day late.
|
||||
|
||||
</xmp><script type="text/javascript" src="http://msoe.us/taylor/gradedown.js"></script></body></html>
|
||||
164
SE1011 Lab Results/1011barnestrL6.htm
Normal file
164
SE1011 Lab Results/1011barnestrL6.htm
Normal file
@@ -0,0 +1,164 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"/><title>barnestr</title></head><body><xmp>
|
||||
|
||||
# Lab 6 -- Simple Class
|
||||
|
||||
* Date: 10-16-2017
|
||||
* Course: SE1011-051
|
||||
* Submitted to: Dr. Chris Taylor
|
||||
|
||||
>> | Earned | Possible | Criteria |
|
||||
>> | ------ | -------- | ------------------------------------------------ |
|
||||
>> | 5 | 10 | UML Class Diagram |
|
||||
>> | 75 | 75 | Met requirements / Technical quality |
|
||||
>> | 10 | 10 | Coding standard compliance and program clarity |
|
||||
>> | 5 | 5 | Following submission instructions |
|
||||
>
|
||||
> # Feedback
|
||||
> * Nice work
|
||||
|
||||
# BuildingCostEstimator.java
|
||||
|
||||
```
|
||||
/*
|
||||
* SE1011
|
||||
* Fall 2017
|
||||
* Lab 6 - BuildingCostEstimator
|
||||
* Name: Trevor Barnes
|
||||
* Created: 10/10/2017
|
||||
*/
|
||||
package barnestr;
|
||||
|
||||
public class BuildingCostEstimator {
|
||||
```
|
||||
> #### Class Javadoc requirements
|
||||
> The [Coding Standard](http://msoe.us/taylor/se1011/CodingStandard) requires
|
||||
> the following:
|
||||
>> Class comments - each class is commented using Javadoc style. The comment
|
||||
>> contains a brief description of the class (not required for a class that
|
||||
>> is the main or driver).
|
||||
|
||||
```
|
||||
private final int SQ_FEET_COST = 130;
|
||||
private final int FULL_BATH_COST = 15000;
|
||||
private final int HALF_BATH_COST = 7000;
|
||||
private final int BEDROOM_COST = 3000;
|
||||
private final int WINDOW_COST = 800;
|
||||
private final int GARAGE_COST = 8000;
|
||||
private int sqFeet;
|
||||
private int numFullBaths;
|
||||
private int numHalfBaths;
|
||||
private int numBeds;
|
||||
private int numWindows;
|
||||
private double numGarages;
|
||||
|
||||
public int getSquareFeet() {
|
||||
return sqFeet;
|
||||
}
|
||||
|
||||
public int getNumFullBaths() {
|
||||
return numFullBaths;
|
||||
}
|
||||
|
||||
public int getNumHalfBaths() {
|
||||
return numHalfBaths;
|
||||
}
|
||||
|
||||
public int getNumBedrooms() {
|
||||
return numBeds;
|
||||
}
|
||||
|
||||
public int getNumWindows() {
|
||||
return numWindows;
|
||||
}
|
||||
|
||||
public double getNumGarages() {
|
||||
return numGarages;
|
||||
}
|
||||
|
||||
|
||||
public double costToBuild() {
|
||||
```
|
||||
> #### Method Javadoc requirements
|
||||
> The [Coding Standard](http://msoe.us/taylor/se1011/CodingStandard) requires
|
||||
> the following:
|
||||
>> Method comments - public methods are commented using Javadoc style,
|
||||
>> with the exception of getters and setters which typically are not commented. For example:
|
||||
>>
|
||||
>> ```
|
||||
/**
|
||||
* This method prints out "Hello" to the person given and
|
||||
* returns the number of letters in the person's name.
|
||||
*
|
||||
* @param name The person to who to say hello.
|
||||
* @return The number of characters in the person's name.
|
||||
*/
|
||||
```
|
||||
|
||||
```
|
||||
return (sqFeet*SQ_FEET_COST)+(numFullBaths*FULL_BATH_COST)+(numHalfBaths*HALF_BATH_COST)+
|
||||
(numBeds*BEDROOM_COST)+(numWindows*WINDOW_COST)+(numGarages*GARAGE_COST);
|
||||
}
|
||||
|
||||
|
||||
public void setSquareFeet(int sqFeet) {
|
||||
this.sqFeet = sqFeet;
|
||||
}
|
||||
|
||||
public void setNumFullBaths(int numFullBaths) {
|
||||
this.numFullBaths = numFullBaths;
|
||||
}
|
||||
|
||||
public void setNumHalfBaths(int numHalfBaths) {
|
||||
this.numHalfBaths = numHalfBaths;
|
||||
}
|
||||
|
||||
public void setNumBedrooms(int numBeds) {
|
||||
this.numBeds = numBeds;
|
||||
```
|
||||
> #### Foolproofing your class
|
||||
> One of the ways that your implementation would fail is if someone were
|
||||
> to ask your class to set one of the attributes to a negative value;
|
||||
> `setNumBedrooms(-50);`, for example.
|
||||
>
|
||||
> While you could claim that it is not your fault that somebody was dumb
|
||||
> enough to try to build a house with -50 bedrooms, it still makes you look
|
||||
> bad because the class you wrote is producing crazying answers. ("You'll pay
|
||||
> me to build my house for me?").
|
||||
>
|
||||
> You can protect against this sort of thing by checking in each of your
|
||||
> `set`Whatever`()` methods to make sure you were not passed a negative
|
||||
> value. You could then return a `boolean` which indicated whether or
|
||||
> not the value had actual been changed by the call to `set`Whatever`()`.
|
||||
> For example, the `setNumBedrooms()` method could look like this:
|
||||
>
|
||||
> ```
|
||||
public boolean setNumBedrooms(int numBedrooms) {
|
||||
boolean changed = false;
|
||||
if(numBedrooms>=0) {
|
||||
this.numBedrooms = numBedrooms;
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
```
|
||||
|
||||
> Of course, it is difficult to completely foolproof your class since fools
|
||||
> are so ingenious.
|
||||
|
||||
```
|
||||
}
|
||||
|
||||
public void setNumWindows(int numWindows) {
|
||||
this.numWindows = numWindows;
|
||||
}
|
||||
|
||||
public void setNumGarages(double numGarages) {
|
||||
this.numGarages = numGarages;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
</xmp><script type="text/javascript" src="http://msoe.us/taylor/gradedown.js"></script></body></html>
|
||||
Reference in New Issue
Block a user