2168-FRCJavaCourse2015-Class2
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
public class Salary | |
{ | |
public static void main(String[] args) | |
{ | |
final double PAY_RATE = 15; //pay rate | |
double pay = 0; // uninitialized variable | |
int hoursWorked = 40; | |
if (hoursWorked > 40) | |
pay = PAY_RATE * 40 + 1.5 * PAY_RATE * (hoursWorked - 40); | |
else | |
pay = PAY_RATE * hoursWorked; | |
System.out.println("You worked " + hoursWorked + " hours"); | |
System.out.println("Your pay rate is $: " + PAY_RATE + " dollars" ); | |
System. out.println("Your salary for the week is $: " + pay); | |
//conditonal operators | |
double pressure = 23.5; | |
double MAX = 100; | |
int age = 15; | |
int score = 93; | |
System.out.println( pressure < MAX ); //true | |
System.out.println( age == 0 ); //false | |
System.out.println( age != 0 ); //true | |
System.out.println( score >= 90 ); //true | |
//String comparison | |
final String MY_NAME = "Kevin"; | |
System.out.println(MY_NAME == "Kevin"); //true | |
System.out.println(MY_NAME == "kevin"); //false | |
boolean choice = true; | |
boolean frenchFries = false; | |
boolean isName = (MY_NAME == "Kevin"); | |
System.out.println("Is name is: " + isName); | |
int time = 1500; | |
int limit = 1800; | |
int max = 2400; | |
int personAge = 20; | |
boolean withGuardian = true; | |
//boolean operators | |
boolean madeIt = (time < limit ) && ( limit < max ); //AND | |
boolean movie = ((personAge > 21) && withGuardian); //OR | |
System.out.println(madeIt); | |
System.out.println(movie); | |
System.out.println(!false); //NOT | |
} | |
} |
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
public class SalaryMethod { | |
public static void main(String[] args) | |
{ | |
final double PAY_RATE1 = 18; //john | |
final double PAY_RATE2 = 20; //mary | |
final double PAY_RATE3 = 17; //steve | |
String name = "Steve"; | |
double hoursWorked = 30; | |
double pay = 0; | |
if (name == "Mary") | |
pay = SalaryMethod.salary(hoursWorked, PAY_RATE2); | |
if (name == "John") | |
pay = SalaryMethod.salary(hoursWorked, PAY_RATE1); | |
if (name == "Steve") | |
pay = SalaryMethod.salary(hoursWorked, PAY_RATE3); | |
System.out.println(name + " worked " + hoursWorked + "hours and paid: $ " + pay); | |
} | |
public static double salary(double hoursWorked, double PAY_RATE) | |
{ | |
if (hoursWorked > 40) | |
return PAY_RATE * 40 + 1.5 * PAY_RATE * (hoursWorked - 40); | |
else | |
return PAY_RATE * hoursWorked; | |
} | |
} |
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
public class SalaryUpgrade { | |
public static void main(String[] args) | |
{ | |
//John : 18hr , 50hrs/week | |
//Mary : 20hr , 30 hrs/week | |
//Steve : 17hr, 40 hrs/week; | |
final double PAY_RATE1 = 18; | |
final double PAY_RATE2 = 20; | |
final double PAY_RATE3 = 17; | |
String name = "John"; | |
int hoursWorked = 50; | |
double pay = 0; | |
if (name == "Mary") | |
{ | |
if (hoursWorked > 40) | |
pay = PAY_RATE2 * 40 + 1.5 * PAY_RATE2 * (hoursWorked - 40); | |
else | |
pay = PAY_RATE2 * hoursWorked; | |
} | |
if (name == "John") | |
{ | |
if (hoursWorked > 40) | |
pay = PAY_RATE1 * 40 + 1.5 * PAY_RATE1 * (hoursWorked - 40); | |
else | |
pay = PAY_RATE1 * hoursWorked; | |
} | |
System.out.println("You worked " + hoursWorked + " hours"); | |
System. out.println("Your salary for the week is $: " + pay); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment