I.T assignment

profilemexmum
i.t_assignment.docx

Code Sample

Statement Type

Explanation

//get the value of score

double score = 75;

if (score >= 60)

{

System.out.println(“Pass”);

}

//the output of this example will be PASS

//Nothing will happen if the given score was //less than 60

if (condition)

{

//then-statements will be executed if the //condition is true

}

else

{

//else-statements will be executed if the //condition is false

}

int option =1;

int cost;

int extra = 0; //can be 0 if no extras are requested, //1 if requested

if (option == 1)

{

if (extra == 1)

{

//extras is requested

cost = 8;

System.out.println(“Customer selected the Standard wash+extra”);

}

else

{

//extras is NOT requested

cost = 6;

System.out.println(“Customer selected the Standard wash”);

}

}

else if (option == 2)

{

if (extra == 1)

{

//extras is requested

cost = cost + 13;

System.out.println(“Customer selected the Deluxe wash+extra”);

}

else

{

//extras is NOT requested

cost = 10;

System.out.println(“Customer selected the Deluxe wash”);

}

}

else if (option == 3)

{

if (extra == 1)

{

//extras is requested

cost = 16;

System.out.println(“Customer selected the Duper Deluxe Wash+extra”);

}

else

{

//extras is NOT requested

cost = 12;

System.out.println(“Customer selected the super deluxe wash”);

}

} //ends the main if

else

{

System.out.println(“invalid entry, please try again”);

}

System.out.println(“Your total cost is” + cost);

//the output of this example will be:

//Customer selected the standard wash

//Your total cost is 6

switch (switch_expression)

{

case label1:

//statements to be executed when label1 = //switch_expression

break;

case label2:

//statements to be executed when label2 = //switch_expression

break;

case label3:

//statements to be executed when label3 = //switch_expression

break;

default:

//statements to be executed when none of

//the above labels matches the //switch_expression

break;

}