Sunday, June 10, 2012

Java Codelab: 1.2 Built-in Data Types

Java Codelab

1.2 Built-in Data Types

¤ Integers

· Literals

Write a literal representing the integer value zero.


0

Write a literal representing the long integer value twelve billion.

12000000000l

Write a hexadecimal integer literal representing the value fifteen.

0xF

· Constants 

Declare an integer constant,  MONTHS_IN_YEAR , whose value is  12 .

final int MONTHS_IN_YEAR = 12 ;

 Declare a constant MONTHS_IN_DECADE , whose value is the value of the constant  MONTHS_IN_YEAR (already declared) multiplied by  10 .

final int MONTHS_IN_DECADE  = MONTHS_IN_YEAR * 10 ;

Declarations

Declare an integer variable named  degreesCelsius .

int degreesCelsius;

Declare a short variable named  patientsAge .

short patientsAge

Declare a long integer variable named  grossNationalProduct .

long grossNationalProduct ;

Declare two integer variables named  profitStartOfQuarter and  cashFlowEndOfYear .

int profitStartOfQuarter, cashFlowEndOfYear ;

Declare and initialize the following variables:
 · monthOfYear , initialized to the value 11
 · companyRevenue , initialized to the value 5666777
 · firstClassTicketPrice , initialized to the value 6000
 · totalPopulation , initialized to the value 1222333

int monthOfYear = 11;
int companyRevenue = 5666777;
int firstClassTicketPrice = 6000;
int totalPopulation = 1222333;

· Operations

Write an expression that computes the sum of two variables  verbalScore and  mathScore (already declared and assigned values).

verbalScore + mathScore

Given the variables  taxablePurchases and  taxFreePurchases (already declared and assigned values), write an expression corresponding to the total amount purchased.

taxablePurchases + taxFreePurchases

Write an expression that computes the difference of the variables  endingTime and  startingTime .

endingTime - startingTime

Given the variables  fullAdmissionPrice and  discountAmount (already declared and assigned values), write an expression corresponding to the price of a discount admission.

fullAdmissionPrice - discountAmount

Given the variable  pricePerCase , write an expression corresponding to the price of a dozen cases.

pricePerCase * 12


Given the variables  costOfBusRental and  maxBusRiders of type  int , write an expression corresponding to the cost per rider (assuming the bus is full). (Do not worry about any fractional part of the expression-- let integer arithmetic, with truncation, act here.)

costOfBusRental / maxBusRiders


Write an expression that computes the remainder of the variable  principal when divided by the variable  divisor . (Assume both are type  int .)

principal % divisor

· Precedence

Write an expression that computes the average of the values  12 and  40 .

(12 + 40) / 2

Write an expression that computes the integer average of the int variables  exam1 and  exam2 (both declared and assigned values).

(exam1 + exam2) /2

¤ Floating Point

· Literals

Write a literal corresponding to the floating point value one-and-a-half.

1.5

Write a literal corresponding to the value of the first 6 digits of PI ("three point one four one five nine").

3.14159

·Declarations

Declare a  float variable named  price .

float price ;

Declare a  double variable named  netWeight

double netWeight ;


 Declare two  double variables, one named  length with a value of  3.5 and the other named  width with a value of  1.55 .

double length = 3.5, width = 1.55 ;

·Operations

Write an expression that computes the sum of two  double variables  total1 and  total2 , which have been already declared and assigned values.

total1 + total2

 Write an expression that computes the difference of two  double variables  salesSummer and  salesSpring , which have been already declared and assigned values. 

salesSummer - salesSpring

You are given two  double variables, already declared and assigned values, named  totalWeight , containing the weight of a shipment, and  weightOfBox , containing the weight of the box in which a product is shipped. Write an expression that calculates the net weight of the product.

totalWeight - weightOfBox

You are given two variables, already declared and assigned values, one of type  double , named  totalWeight , containing the weight of a shipment, and the other of type  int , named  quantity , containing the number of items in the shipment. Write an expression that calculates the weight of one item.

totalWeight / quantity

You are given two variables, already declared and assigned values, one of type  double , named  price , containing the price of an order, and the other of type  int , named  totalNumber , containing the number of orders. Write an expression that calculates the total price for all orders.

price * totalNumber

Java Codelab: 1.1 Your first program

Java Codelab

1.1 Your first program

Write a statement that prints  Hello, world to the screen.

System.out.println("Hello, world");


 Write a complete main  method that prints  Hello, world to the screen.  

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

 Suppose your name was Alan Turing. Write a statement that would print your last name, followed by a comma, followed by a space and your first name.  

System.out.print("Turing, Alan");

Suppose your name was George Gershwin. Write a complete main method that would print your last name, followed by a comma, followed by a space and your first name. 

public static void main(String[]args){
System.out.println("Gershwin, George");
}

Write a complete program whose class name is Hello and that displays  Hello, world on the screen.

public class Hello {
public static void main(String[]args){
System.out.println("Hello, world");
}
}




Sunday, November 21, 2010

Four Loko




     "Let's ban Four Loko!" Really? Let's look at what the news reports and let's use our brains. News: Hospital visits increase due to college students drinking Four Lokos. 19 year old female college student drives into a house due to beer pong using four loko. Do you see the pattern? COLLEGE STUDENT. It's reported one can of SND(said name drink) is equivalent to four beers. How do we stop hospitalization due to SND? The same way we stop it with regular liquor or alcohol. Drink in moderation! Apparently college students are smart enough to get in but too damn stupid to use their brain. 
     Oh my word!! A 19 year old crashed into a house after playing beer pong while using SND!!! Never mind the fact she was underage, or the fact that she was DRINKING AND DRIVING! It's amazing they don't give two shits about the two facts I just pointed out. They are only point out what she was drinking. Maybe if they were as worried about alcohol and liquor the the same way they are about this drink there would be less DUI's, DWI's, domestic violence, and accidental deaths. The owners of the house should sue the teen and the of age asshole who hosted the party.
     The FDA is saying alcohol and caffeine is not a good mix. Sparks was here long before Four Loko and now it's a problem? It's clearly obvious that they are attacking this drink due to it being new to the market. Personally I don't see how people can drink it.. it tastes like shit. To each his own I suppose but, instead of banning the drink the ban needs to be on the remedial teens who don't know the meaning of moderation.