-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79b2459
commit c4d8d71
Showing
13 changed files
with
359 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |