Skip to content

Commit 0a45cd3

Browse files
Finished Program Challenge Ch 3 Ex 3, 4, 7, 15, 16
1 parent ca87294 commit 0a45cd3

File tree

5 files changed

+261
-0
lines changed

5 files changed

+261
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* This program was written by Kyle Martin on 5/27/2021 for CPT421 Java Programming Principles 1 during Summer Session 1
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program calculates the total service fee based on the amount of checks written in a month.
10+
*/
11+
import java.text.DecimalFormat;
12+
import java.text.NumberFormat;
13+
import java.util.Scanner;
14+
15+
public class BankCharges {
16+
public static void main(String[] args) {
17+
// Scanner
18+
Scanner userInput = new Scanner(System.in);
19+
NumberFormat moneyFormat = new DecimalFormat("#,###.##");
20+
21+
// Declarations
22+
final double MONTHLY_BASE_CHARGE = 10.00;
23+
final double LESS_THAN_TWENTY_CHECKS = 0.10;
24+
final double TWENTY_TO_THIRTY_NINE_CHECKS = 0.08;
25+
final double FORTY_TO_FIFTY_NINE_CHECKS = 0.06;
26+
final double SIXTY_PLUS_CHECKS = 0.04;
27+
28+
double totalMonthlyServiceFee = 0;
29+
30+
// Questionnaire
31+
System.out.println("Welcome the the Bank Service Fee inquiry system.");
32+
System.out.println( "The Bank charges a flat rate fee of $" + moneyFormat.format(MONTHLY_BASE_CHARGE) +
33+
" per month.");
34+
System.out.println( "The Bank also charges a fee of: \n" +
35+
"$" + LESS_THAN_TWENTY_CHECKS + " each check for less than 20 checks a month written \n" +
36+
"$" + TWENTY_TO_THIRTY_NINE_CHECKS + " each check for 20-39 checks a month written \n" +
37+
"$" + FORTY_TO_FIFTY_NINE_CHECKS + " each check for 40-59 checks a month written \n" +
38+
"$" + SIXTY_PLUS_CHECKS + " each check for 60+ checks a month written");
39+
System.out.println("How many checks did you write this month? Ex. 10 for 10 checks");
40+
int checksWritten = userInput.nextInt();
41+
42+
// Calculations
43+
if (checksWritten >= 60) {
44+
totalMonthlyServiceFee = MONTHLY_BASE_CHARGE + (SIXTY_PLUS_CHECKS * checksWritten);
45+
} else if (checksWritten <= 59 && checksWritten >= 40) {
46+
totalMonthlyServiceFee = MONTHLY_BASE_CHARGE + (FORTY_TO_FIFTY_NINE_CHECKS * checksWritten);
47+
} else if (checksWritten <= 39 && checksWritten >= 20) {
48+
totalMonthlyServiceFee = MONTHLY_BASE_CHARGE + (TWENTY_TO_THIRTY_NINE_CHECKS * checksWritten);
49+
} else if (checksWritten < 20 && checksWritten >= 1) {
50+
totalMonthlyServiceFee = MONTHLY_BASE_CHARGE + (LESS_THAN_TWENTY_CHECKS * checksWritten);
51+
} else {
52+
System.out.println("Please enter a correct solid number of checks.");
53+
}
54+
System.out.println( "You wrote " + checksWritten + " this month. Your charge comes to $" +
55+
moneyFormat.format(totalMonthlyServiceFee));
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This program was written by Kyle Martin on 5/27/2021 for CPT421 Java Programming Principles 1 during Summer Session 1
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program calculates the total amount of points a book club member earns this month.
10+
*/
11+
import java.util.Scanner;
12+
13+
public class BookClub {
14+
public static void main(String[] args) {
15+
// Scanner
16+
Scanner userInput = new Scanner(System.in);
17+
18+
// Declarations
19+
final int ONE_BOOK = 5, TWO_BOOKS = 15, THREE_BOOKS = 30, FOUR_PLUS_BOOKS = 60;
20+
int totalBookClubPoints = 0;
21+
22+
// Questionnaire
23+
System.out.println( "Welcome to Serendipity Booksellers Book Club! \n" +
24+
"Lets calculate your points this month!");
25+
System.out.println("How many books did you purchase this month? Example: 2 for 2 books.");
26+
int booksPurchased = userInput.nextInt();
27+
28+
// Calculation
29+
if (booksPurchased >= 4) {
30+
totalBookClubPoints = FOUR_PLUS_BOOKS;
31+
} else if (booksPurchased == 3) {
32+
totalBookClubPoints = THREE_BOOKS;
33+
} else if (booksPurchased == 2) {
34+
totalBookClubPoints = TWO_BOOKS;
35+
} else if (booksPurchased == 1) {
36+
totalBookClubPoints = ONE_BOOK;
37+
}
38+
39+
// Output
40+
System.out.println("You have earned " + totalBookClubPoints + " points this month!");
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This program was written by Kyle Martin on 5/27/2021 for CPT421 Java Programming Principles 1 during Summer Session 1
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program calculates the BMI of the user.
10+
*/
11+
import java.text.DecimalFormat;
12+
import java.text.NumberFormat;
13+
import java.util.Scanner;
14+
15+
public class BodyMassIndexCalculator {
16+
public static void main(String[] args) {
17+
// Scanner and number format
18+
Scanner userInput = new Scanner(System.in);
19+
NumberFormat bmiFormat = new DecimalFormat("##.##");
20+
21+
// Questionnaire:
22+
System.out.println("Welcome to the Body Mass Index calculator!");
23+
System.out.println("Please type in your weight in pounds. Ex. 185 for 185 lbs.");
24+
double weight = userInput.nextDouble();
25+
System.out.println("Please type in your height in inches. Ex 67 for 67 inches.");
26+
double height = userInput.nextInt();
27+
28+
// Calculations:
29+
double bmi = (weight * 703) / (height * height);
30+
31+
// Output:
32+
System.out.println("Your BMI is: " + bmiFormat.format(bmi) + ".");
33+
if (bmi < 18.5){
34+
System.out.println("You are underweight");
35+
} else if (bmi < 25){
36+
System.out.println("You are normal weight");
37+
} else {
38+
System.out.println("You are overweight.");
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* This program was written by Kyle Martin on 5/27/2021 for CPT421 Java Programming Principles 1 during Summer Session 1
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program calculates the average test scores of 3 tests and reports what grade they received on average.
10+
*/
11+
12+
import java.text.DecimalFormat;
13+
import java.text.NumberFormat;
14+
import java.util.Scanner;
15+
16+
public class TestScoresGrade {
17+
public static void main(String[] args) {
18+
// Scanner & Number Format
19+
Scanner userInput = new Scanner(System.in);
20+
NumberFormat formattedScore = new DecimalFormat("##.##");
21+
22+
// Questionnaire
23+
System.out.println("Welcome to the Test Score Average Calculator!");
24+
System.out.println("This application will take the average of three test scores and calculate your average as "+
25+
"well as tell you your grade.");
26+
System.out.println("What was the score of your first test? Ex. 90 for 90%.");
27+
double testOneScore = userInput.nextDouble();
28+
System.out.println("What was the score of your second test? Ex. 75 for 75%.");
29+
double testTwoScore = userInput.nextDouble();
30+
System.out.println("What was the score of your third test? Ex. 84 for 84%.");
31+
double testThreeScore = userInput.nextDouble();
32+
33+
// Calculation
34+
double averageScore = (testOneScore + testTwoScore + testThreeScore) / 3;
35+
36+
/*
37+
Output Section
38+
* 90-110 A
39+
* 80-89 B
40+
* 70-79 C
41+
* 60-69 D
42+
* < 60 F
43+
*/
44+
int testAverageCase;
45+
if (averageScore >= 90 && averageScore <= 110) {
46+
testAverageCase = 1;
47+
} else if (averageScore >= 80 && averageScore <= 89) {
48+
testAverageCase = 2;
49+
} else if (averageScore >= 70 && averageScore <= 79) {
50+
testAverageCase = 3;
51+
} else if (averageScore >= 60 && averageScore <= 69) {
52+
testAverageCase = 4;
53+
} else {
54+
testAverageCase = 5;
55+
}
56+
57+
switch (testAverageCase) {
58+
case 1 -> System.out.println( "Your average test score was: " + formattedScore.format(averageScore) +
59+
" and your average grade was a 'A'.");
60+
case 2 -> System.out.println( "Your average test score was: " + formattedScore.format(averageScore) +
61+
" and your average grade was a 'B'.");
62+
case 3 -> System.out.println( "Your average test score was: " + formattedScore.format(averageScore) +
63+
" and your average grade was a 'C'.");
64+
case 4 -> System.out.println( "Your average test score was: " + formattedScore.format(averageScore) +
65+
" and your average grade was a 'D'.");
66+
case 5 -> System.out.println( "Your average test score was: " + formattedScore.format(averageScore) +
67+
" and your average grade was a 'F'.");
68+
default -> System.out.println( "You entered your scores incorrectly. Please try again.");
69+
}
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* This program was written by Kyle Martin on 5/27/2021 for CPT421 Java Programming Principles 1 during Summer Session 1
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program takes three names that the user inputs and then sorts them in alphabetical order.
10+
*/
11+
import java.util.Scanner;
12+
13+
public class SortedNames {
14+
public static void main(String[] args) {
15+
// Scanner
16+
Scanner userInput = new Scanner(System.in);
17+
18+
// Initial Declarations
19+
final int NUMBER_OF_NAMES_INPUTTED = 3;
20+
String namePlaceHolder;
21+
String[] names = new String[NUMBER_OF_NAMES_INPUTTED];
22+
23+
// Questionnaire
24+
System.out.println("""
25+
Welcome to the Name Sorter Application!\s
26+
Please enter up to three names to be sorted\s
27+
Example: Jim, Bob, Jeff""");
28+
29+
// Logic for sorting Names
30+
for (int i = 0; i < NUMBER_OF_NAMES_INPUTTED; i++) {
31+
names[i] = userInput.nextLine();
32+
}
33+
for (int i = 0; i < NUMBER_OF_NAMES_INPUTTED; i++) {
34+
for (int j = i + 1; j < NUMBER_OF_NAMES_INPUTTED; j++) {
35+
if (names[i].compareTo(names[j])>0) {
36+
namePlaceHolder = names[i];
37+
names[i] = names[j];
38+
names[j] = namePlaceHolder;
39+
}
40+
}
41+
}
42+
43+
// Output
44+
System.out.println("Names are now sorted: ");
45+
for (int i = 0; i < NUMBER_OF_NAMES_INPUTTED - 1; i++) {
46+
System.out.print(names[i] + ", ");
47+
}
48+
System.out.println(names[NUMBER_OF_NAMES_INPUTTED - 1]);
49+
}
50+
}

0 commit comments

Comments
 (0)