Mr. Truncale - Robert E. Lee High School
  • Home
  • Digital Media
    • HTML
  • Video Game Design
  • Comp. Programming I
  • Comp. Programming II
  • AP Computer Science
  • 3D Printing
  • Teacher Resources
  • Contact Me

Java - If Labs 1 - 3


1. Discount 
Make a class called Discount. Get the input (double) bill. Then determine the amount of discount a person should receive.  If the bill is more than 2000, then the person should receive a 15% discount.  If the bill is 2000 dollars or less, the person does not receive a discount of any kind.
//SAMPLE CODE

//DECLARE VARIABLES
double bill;
Scanner keyboard = new Scanner(System.in);

//GET INPUT FOR BILL

//MAKE DECISIONS (CHANGE BILL)
//IF BILL > 2000 BILL = BILL *.85

//PRINT OUT RESULTS
System.out.println("Your final bill is " + bill);
TURN IN

2. OddsOrEven
Make a class called OddsOrEven. Write a program that reads in a number and determines if that number is even or odd.  An even number has a remainder of zero when being divided by two.  An odd number is any number that does not have a remainder of zero when being divided by two. 


num%2 == 1 ---> is odd
num%2 == 0 ---> is even  
//SAMPLE CODE

//DECLARE VARIABLES
int num;
Scanner keyboard = new Scanner(System.in);

//GET INPUT

//MAKE DECISIONS AND PRINTOUT RESULTS
//IF ODD PRINT OUT "NUMBER IS ODD"
//IF EVEN PRINT OUT "NUMBER IS EVEN"
TURN IN

3. TruckDistance
Make a class called TruckDistance.  The Jones Trucking Company tracks the location of each of its trucks on a grid similar to an (x, y) plane. The home office is at location (0, 0).  Read the coordinates of truck A and the coordinates of truck B and determine which is closer to the office.  

Distance formula: Math.sqrt( Math.pow(x1 - x2, 2) +  Math.pow(y1 - y2, 2) )

Each collection contains 4 integers: the x-coordinate and then the y-coordinate of truck A followed by the x-coordinate and then the y-coordinate of truck B.
//SAMPLE CODE

//DECLARE VARIABLES
double truck1X;
double truck1Y;
double truck2X;
double truck2Y;
double truck1Distance;
double truck2Distance;
Scanner keyboard = new Scanner(System.in);

//GET INPUT FOR BOTH TRUCKS X AND Y'S

//MAKE DECISIONS
 AND PRINTOUT RESULTS
//IF TRUCK1DISTANCE < TRUCK2DISTANCE PRINTOUT "TRUCK 1 IS CLOSER."
//IF TRUCK2DISTANCE < TRUCK1DISTANCE PRINTOUT "TRUCK 2 IS CLOSER."

TURN IN

Robert E. Lee High School
1809 Market
Baytown, TX 77520
281-420-4535
digital media | computer programming I and II | BIM
ap computer science | architectural cad | video game design
national technical honor society | contact me