Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
profjpbaugh authored Jan 27, 2022
1 parent 79b2459 commit c4d8d71
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 0 deletions.
18 changes: 18 additions & 0 deletions section3/ContinueBreak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


public class ContinueBreak {
public static void main(String[] args) {
int count = 0;

while(count < 10) {

if(count == 5) {
count++;
break;
}
System.out.print(count + "\t");

count++;
}//end while
}//end main
}
20 changes: 20 additions & 0 deletions section3/ControlStatementsIntro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

public class ControlStatementsIntro {
public static void main(String[] args) {
int age = 19;

if(age >= 16) {
System.out.println("You can drive!");
}
else {
System.out.println("You cannot drive yet!");
}//end if-else

System.out.println(); //add some newline space

for(int i = 1; i <= age; i++) {
System.out.println("Happy Birthday " + i);
}//end for

}//end main
}
14 changes: 14 additions & 0 deletions section3/DiceSimulation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.util.Random;

public class DiceSimulation {
public static void main(String[] args) {
Random random = new Random();

int diceVal;

for(int i = 0; i < 10; i++) {
diceVal = random.nextInt(6) + 1;
System.out.println(diceVal);
}//end for
}//end main
}
19 changes: 19 additions & 0 deletions section3/DivisibleByThree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.Scanner;

public class DivisibleByThree {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int input;

System.out.println("Please enter your integer");
input = keyboard.nextInt();

if(input % 3 == 0) {
System.out.println(input + " is divisible by 3");
}
else {
System.out.println(input + " is NOT divisible by 3");
}

}//end main
}
17 changes: 17 additions & 0 deletions section3/EvenOnly.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

public class EvenOnly {
public static void main(String[] args) {
int count = 0;

while(count < 10) {

if(count % 2 != 0) {
count++;
continue;
}
System.out.println(count);

count++;
}//end while
}//end main
}
22 changes: 22 additions & 0 deletions section3/Fraternity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.Scanner;

public class Fraternity {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int age;
char gender;

System.out.print("Enter your age:\t");
age = keyboard.nextInt();

System.out.print("Enter your gender:\t");
gender = keyboard.next().charAt(0);

if(age >= 19 && gender == 'M') {
System.out.println("You can join the fraternity.");
}
else {
System.out.println("Sorry, you cannot join the fraternity.");
}//end if-else
}//end main
}
40 changes: 40 additions & 0 deletions section3/GradeFun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.util.Scanner;

public class GradeFun {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);

char grade;

System.out.println("Enter a grade");
grade = keyboard.next().charAt(0);

switch(grade) {
case 'A':
case 'a':
System.out.println("Great job!");
break;
case 'B':
case 'b':
System.out.println("Good job.");
break;
case 'C':
case 'c':
System.out.println("You can do better.");
break;
case 'D':
case 'd':
System.out.println("You're getting pretty close to failing");
break;
case 'F':
case 'f':
System.out.println("You are failing the course!");
break;
default:
System.out.println("You have entered an invalid grade.");
}//end switch



}//end main
}
47 changes: 47 additions & 0 deletions section3/Proj3_1_LearningPackages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import java.util.Scanner;

public class Proj3_1_LearningPackages {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int packageNumber;
int howManyCourses;
int baseCost;
int costPerCourse;
int numIncluded;
int totalCost;

System.out.println("Which of the packages do you want? 1,2, or 3?");
packageNumber = keyboard.nextInt();

System.out.println("How many courses did you enroll in this month?");
howManyCourses = keyboard.nextInt();

if(packageNumber == 1) {
baseCost = 10;
costPerCourse = 6;
numIncluded = 2;
}
else if(packageNumber == 2) {
baseCost = 12;
costPerCourse = 4;
numIncluded = 4;
}
else {
//package 3
baseCost = 15;
costPerCourse = 3;
numIncluded = 6;
}//end if-else chain

//calculate total cost
if(howManyCourses > numIncluded) {
totalCost = baseCost + (howManyCourses - numIncluded) * costPerCourse;
}
else {
totalCost = baseCost;
}

System.out.println("Total cost is $" + totalCost);

}//end main
}
43 changes: 43 additions & 0 deletions section3/Proj3_3_GuessTheNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.util.Random;
import java.util.Scanner;

public class Proj3_3_GuessTheNumber {

public static void main(String[] args) {
int ourGuess;
int computerNumber;
int guessCount = 0;
Random random = new Random();
boolean guessedNumber = false;
Scanner keyboard = new Scanner(System.in);

computerNumber = random.nextInt(100) + 1;

while(!guessedNumber) {
System.out.println("Enter your integer guess");
ourGuess = keyboard.nextInt();
guessCount++;

if(ourGuess >= 1 && ourGuess <= 100) {
if(ourGuess == computerNumber) {
System.out.println("Congratulations! You guessed the number in " +
guessCount + " guesses! Thanks for playing!");

guessedNumber = true;
}
else if(ourGuess > computerNumber) {
System.out.println("Your guess was too high!");
}
else { //too low!
System.out.println("Your guess was too low!");
}
}
else {
//invalid guess
System.out.println("That was a wasted guess! You must pick a number between 1 and 100, inclusive!");
}

}//end while

}//end main
}
19 changes: 19 additions & 0 deletions section3/RandomFun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.Random;

public class RandomFun {
public static void main(String[] args) {
Random random = new Random();
int myRandomNumber;

myRandomNumber = random.nextInt();
System.out.println("number is:\t" + myRandomNumber);

myRandomNumber = random.nextInt(1000); //0 - 999
System.out.println("0 through 999?\t" + myRandomNumber);

//shifting
myRandomNumber = random.nextInt(1000) + 1; //1 - 1000
System.out.println("1 through 1000?\t" + myRandomNumber);

}//end main
}
48 changes: 48 additions & 0 deletions section3/RepetitionFun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.util.Scanner;

public class RepetitionFun {
public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in);
int input;

//priming read
System.out.println("Enter a non-negative integer");
System.out.println("Or negative to exit");
input = keyboard.nextInt();

while(input >= 0) {
System.out.println(input);

System.out.println("Enter a non-negative integer");
System.out.println("Or negative to exit");
input = keyboard.nextInt();
}//end while

System.out.println("Done!");



// int count = 0;
//
// while(count < 10) {
// System.out.println(count);
// count++;
// }//end while

// int count2 = 15;
//
// do {
// System.out.println(count2);
// count2++;
// }
// while(count2 < 10);

// for(int i = 0; i < 10; i++) {
// System.out.println(i);
// }//end for



}//end main
}
27 changes: 27 additions & 0 deletions section3/SelectionFun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.Scanner;

public class SelectionFun {
public static void main(String[] args) {
int age;
Scanner keyboard = new Scanner(System.in);

System.out.println("Welcome to the Pub and Grille.");

System.out.println("Please enter your age");
age = keyboard.nextInt();

if(age >= 21) {
System.out.println("Here, have a beer.");
}
else if(age >= 16) {
System.out.println("Here have a Coke!");
System.out.println("At least you can drive!");
}
else {
System.out.println("Here have a Coke!");
}

System.out.println("Thanks for coming to the Pub and Grille!");

}
}
25 changes: 25 additions & 0 deletions section3/SumFun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.util.Scanner;

public class SumFun {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int sum = 0;
int input;

//priming read
System.out.println("Enter non-negative to add to sum");
System.out.println("Enter a negative to exit!");
input = keyboard.nextInt();

while(input >= 0) {
sum += input; //sum = sum + input;
System.out.println("Enter non-negative to add to sum");
System.out.println("Enter a negative to exit!");
input = keyboard.nextInt();
}//end while

System.out.println("Sum is " + sum);


}//end main
}

0 comments on commit c4d8d71

Please sign in to comment.