Nested if statement Academic Essay

Write a nested if statement to display the following information
(Run the code in the IDE and save your program as Selection1.java)
Speed Action (print to screen)
>80 Lose licence
70-80 3-6 points on licence
60-70 Caution
<60 Within speed limit
Task 2:
Write a code fragment that reads in a double and outputs a sentence “Between 0 and 5.5” or “Not between 0 and 5.5”, depending on the value read in.
(Run the code in the IDE and save your program as Selection2.java)
Task 3:
Write a code fragment to read in 3 integers and print out the largest.
(Run Run the code in the IDE and save your program as Selection3.java)
Task 4:
To create a histogram for a set of numbers in the range 1 to 50, we have to find out what bin a number will be put into.
(Run Run the code in the IDE and save your program as Selection4.java)
The bins will be spaced as follows
Bin 1: 1-10
Bin 2: 11-20
Bin 3: 21-30
Bin 4: 31-40
Bin 5: 41-50
Write a code fragment that asks the user to enter a number between 1 and 50 and then outputs the bin number in which it would be put.


Task 5: Write a switch statement that prints a message
(Run Run the code in the IDE and save your program as Selection5.java)
By entering a mark (from 0-100), a message will be displayed on the screen and indicates whether grade (a character) the mark is – ‘A’,’B’ or ‘C’, in which case print “You Have Passed”, or ‘D’, ‘E’ in which case print “You have failed: You must resit the exam”, or ‘F’, then print out “You have failed: You cannot resit the exam”. Otherwise print out “Unknown Grade”
Grade A: 70-100
Grade B: 60-70
Grade C: 50-60
Grade D: 40-50
Grade E: 30-40
Grade F: below 30
Task 6: Repeat exercise 5 using a nested if statement instead of a switch statement
(Run Run the code in the IDE and save your program as Selection6.java)
Task 7: Insert brackets to clarify the precedence of the following expressions
(Record your results on the lab sheet)
i. a>b == a<c || a>2 && b!=0
ii. a!=b && c>a || a<=d && c==0
Task 8: Evaluate the following logical expressions.
(Check your answers by compiling the code fragments in main; and record your results on the lab sheet)
Insert brackets to clarify you understand the precedence rules.
int a=2,b=3,c=4,d=4;
char first=’f’, second=’F’;
i. a<b || c!=d
ii. a<b && c!=d
iii. (b==(a+1)) && c<=d && ((a+b)< (c+d)/2)
iv. first>’A’ && first<‘Z’
v. a>b == a<c || a>2 && b!=0





Task 9:
De Morgan’s laws for Boolean algebra states that, given two Boolean variables a and b
(Check your answers by compiling the code fragments in main; and save your program as Selection7.java)
i. NOT(a AND b) = NOT(a) OR NOT(b)
ii. NOT(a OR b) = NOT(a) AND NOT(b)
Write Java expressions for these laws, assuming two Boolean variables a and b have been declared. Verify that these laws are correct.
Task 10:
Write a program to calculate the cost of delivery for an order from a local supermarket. The current rates for different items are shown below
(Save your program as AmazonDelivery.java) (JOptionPane)!!!
Item Delivery cost per item per delivery charge
Book 3.26p £2.16
CD 1.39p £1.16
DVD 3.49p £1.16
Game 12.60p £1.59
The “per delivery charge” is a single charge per order. It is always charged at the most expensive rate for any of the items ordered.
For example:
· 1 Book – would cost a total of £5.42 (1 x £3.26 + £2.16)
· 2 CDs + 1 Game – would cost a total of £16.97 (2 x £1.39 + 1 x £12.60 + £1.59) – the delivery charge is £1.59 as the delivery charge of a game is greater than that of a CD.
The requirements of the program are:
a) Ask the user to enter how many of each item they are buying;
b) Make sure that the input is valid, i.e. an integer greater than zero.
c) Calculate the cost of delivery.
d) Print out a neatly formatted break down of the delivery cost for example:
Item Number Cost Total
Book 2 3.26 £6.52
CD 4 1.39 £5.56
DVD 0 3.49 £0.00
Game 1 12.60 £12.60
—————————————————————————-
Delivery Charge £2.16
—————————————————————————-
Total £26.84

 

Looking for the best essay writer? Click below

to have a customized paper written as per your

requirements.

find the cost of your paper

Is this question part of your assignment?

Place order