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 843b5e0 commit 79b2459
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 0 deletions.
34 changes: 34 additions & 0 deletions section2/ArithmeticFun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


public class ArithmeticFun {
public static void main(String[] args) {
int a = 10;
int b = 15;

//e.g., BINARY operators
int result = a + b;
int difference = a - b;
int product = a * b;
int quotient = b / a;
int remainder = b % a;

System.out.println("result is " + result);
System.out.println("diff is " + difference);
System.out.println("product is " + product);
System.out.println("quotient is " + quotient);
System.out.println("remainder is " + remainder);

result += 20; //result = result + 20
System.out.println("result is now " + result);

//UNARY operators
result++; //++result;
System.out.println("result++ " + result);

result--; //--result;
System.out.println("result-- " + result);

product *= 2; //product = product * 2;
System.out.println("final value of product is " + product);
}
}
18 changes: 18 additions & 0 deletions section2/CommentFun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
John Baugh
Learning Some Java 101
This is a multiline comment
July 30, 2060
*/

public class CommentFun {
/*
main is the entry point to the application.
*/

public static void main(String[] args) {
System.out.println("Printing stuff"); //print stuff to console
//this doesn't print
//these are single line comments
}//end main
}
10 changes: 10 additions & 0 deletions section2/ConversionFun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


public class ConversionFun {
public static void main(String[] args) {
double myDouble = 3.14;
float myFloat = 3.14f; //narrowing/lossy conversion
double yourDouble = myFloat; //widening/lossless conversion

}//end main
}
9 changes: 9 additions & 0 deletions section2/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

public class HelloWorld {

public static void main(String[] args) {
System.out.println("Hello world!");
System.out.println("Hello John!");

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

public class KeyboardInput {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String name;
String city;
int age;
double dubInput;

System.out.println("What is your name?");
name = keyboard.nextLine();

System.out.println("What's your age?");
age = keyboard.nextInt();
keyboard.nextLine(); //consume the newline

System.out.println("What's your real number?");
dubInput = keyboard.nextDouble();
keyboard.nextLine();
dubInput *= 2; //dubInput = dubInput * 2;

System.out.println("What city do you live in?");
city = keyboard.nextLine();

System.out.println("Hello, " + name);
System.out.println("age is " + age);
System.out.println("city is " + city);
System.out.println("Twice your number is " + dubInput);
}//end main
}
20 changes: 20 additions & 0 deletions section2/LogicalFun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


public class LogicalFun {
public static void main(String[] args) {
boolean isRaining = false;
boolean isWarm = false;

boolean combined = isRaining && isWarm;

System.out.println("Is it raining and warm?: " + combined);

combined = isRaining || isWarm;

System.out.println("Is it raining OR warm?: " + combined);

combined = !isRaining;

System.out.println("Is it NOT raining outside?: " + combined);
}//end main
}
23 changes: 23 additions & 0 deletions section2/Proj2_1_AverageOfThree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;

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

double num1;
double num2;
double num3;
double average;

System.out.println("Please enter three numbers");
num1 = keyboard.nextDouble();
num2 = keyboard.nextDouble();
num3 = keyboard.nextDouble();
keyboard.nextLine(); //good habit

average = (num1 + num2 + num3) / 3.0;

System.out.println("Average is " + average);

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


public class Proj2_2_MadLibsClone {

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

String adjective1;
String girlsName;
String adjective2;
String occupation1;
String placeName;
String clothing;
String hobby;
String adjective3;
String occupation2;
String boysName;
String mansName;

System.out.print("Enter an adjective\t");
adjective1 = keyboard.nextLine();

System.out.print("Enter a girl's name:\t");
girlsName = keyboard.nextLine();

System.out.print("Enter another adjective:\t");
adjective2 = keyboard.nextLine();

System.out.print("Enter an occupation:\t");
occupation1 = keyboard.nextLine();

System.out.print("Enter the name of a place:\t");
placeName = keyboard.nextLine();

System.out.print("Enter the name of a piece of clothing:\t");
clothing = keyboard.nextLine();

System.out.print("Enter the name of a hobby:\t");
hobby = keyboard.nextLine();

System.out.print("Enter another adjective:\t");
adjective3 = keyboard.nextLine();

System.out.print("Enter another occupation:\t");
occupation2 = keyboard.nextLine();

System.out.print("Enter a boy's name:\t");
boysName = keyboard.nextLine();

System.out.print("Enter a man's name:\t");
mansName = keyboard.nextLine();

System.out.println();

System.out.println("There once was a " + adjective1 + " girl named " + girlsName + " who was a " +
adjective2 + " " + occupation1 + " in the Kingdom of " + placeName + ".");

System.out.println("She loved to wear " + clothing + " and to " + hobby + ". She wanted to marry the " +
adjective3 + " " + occupation2 + " named " + boysName + " but her father, King " + mansName +
" forbid her from seeing him.");
}//end main
}
36 changes: 36 additions & 0 deletions section2/RelationalFun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

public class RelationalFun {
public static void main(String[] args) {
boolean myBool = true;
boolean yourBool = false;
int myAge = 37;
int yourAge = 20;
int bobsAge = 20;

String myName = "John";
String yourName = "Johnny";

System.out.println("myBool is " + myBool);
System.out.println("yourBool is " + yourBool);

//relational operations
boolean ageComparison = myAge > yourAge;
System.out.println("myAge > yourAge?: " + ageComparison);

ageComparison = yourAge > bobsAge;
System.out.println("yourAge > bobsAge?:" + ageComparison);

ageComparison = yourAge == bobsAge;
System.out.println("yourAge == bobsAge?: " + ageComparison);

boolean nameComparison = myName.equals(yourName);
System.out.println("do names match?: " + nameComparison);

int currentAge = 37;

boolean isGreater21 = currentAge >= 21;

System.out.println("currentAge >= 21?: " + isGreater21);

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


public class VariableFun {
public static void main(String[] args) {
int myAge; //declaration
myAge = 19; //initialization

final int SOME_NUM = 150;

String name = "Billy";

String myHomeTown = "Dearborn";

System.out.println(name + " is " + myAge);
System.out.println(myHomeTown);
}
}

0 comments on commit 79b2459

Please sign in to comment.