Download the L04.zip file and extract the files to your cs125 folder in your home directory. You will use these files to complete this week's lab exercises.
This lab covers lectures 6 and 7. You are expected to know about Boolean expressions and selection. A quick overview is given here.
Create the Java file IfElse.java, write a program
that will read in 2 integers (using the Scanner class) and determine if the two numbers have
the same parity (i.e., are they both odd or both even).
If they have the same parity, the program should output "Same parity" and
otherwise output "One number is odd, the other is even".
(Hint: remember %.)
Evaluate the following Boolean expressions. Assume that A, B, C and D are Boolean variables where A is FALSE, B is TRUE , C is TRUE and D is FALSE.
Paste your answers into the box below. The answers should only be TRUE or FALSE and should be one response to a line.
Open CharRecognition.java and write a program that will identify the first character input by the user (you'll need to use a Scanner object, the method nextLine(), and a String method to do that). Your program must identify the character as one of the following:
Note that you can compare characters in the same way as you compare integers using <, <=, >, >=, and ==. The letters 'a' - 'z' are consecutive, the letters 'A' - 'Z' are consecutive, and the digits '0' - '9' are consecutive when comparing character values ('1'-'0' = 1, '2'-'0' = 2, ... '9'-'0' = 9). For example,
char firstLetter = 'a'; char secondLetter = 'b'; char thirdLetter = 'z'; System.out.println(firstLetter < secondLetter); // outputs true System.out.println(thirdLetter > firstLetter); // outputs true
| Sample input | Sample output |
|---|---|
| p | letter |
| W | letter |
| 7 | digit |
| * | other |
| whitespace | |
| ; | other |
Once completed paste ALL your code in the below area and submit.
Review the code in the file AcademicStanding.java. Try tracing through the code by hand for the following inputs to predict the output. You can check your answers by running the program and inputting the values given below. Note that, on a written exam, you will not have access to a computer to run code. It is essential that you understand how to trace code, so we strongly suggest that you try tracing through this code before running the code to get the solutions.
| CAV | MAV | numExcluded | numCredits | Standing? |
|---|---|---|---|---|
| 87 | 76 | 0.0 | 8.0 | |
| 80 | 79 | 1.0 | 1.5 | |
| 80 | 58 | 0.5 | 2.0 | |
| 86 | 51 | 1.0 | 1.5 | |
| 61 | 72 | 2.5 | 4.5 | |
| 51 | 51 | 2.0 | 3.0 |
Submit the standings you get below with each standing being seperated by a comma.
The Canada Revenue Agency (CRA) collects income taxes. This question is based on Schedule 1 of the T1 tax form. If you would like to see the document it is available here. To eliminate some possible confusion, you do not NEED to fully understand the TD1 document to complete this question, all the information you need to be successful is given below.
The income tax you pay depends upon your earned income and on different rates as follows.
As an example, if your income were $70,000 you would owe 19% of the first $20,000 ($3,800), 27% of the next $30,000 ($8,100) and 42% of the remaining $20,000 ($8,400) giving total taxes of $20,300.
Write a program that will ask the user for his or her income and then report the income and taxes. Below are examples of Earned income values, and the correct tax values. You may use these as a guide to check the accuracy of your program. You may assume the user inputs only the numeric value of their income, and not the "$".
Earned income: $10000.0 Taxes: $1900.0 Earned income: $20000.0 Taxes: $3800.0 Earned income: $30000.0 Taxes: $6500.0 Earned income: $50000.01 Taxes: $11900.004200000001 Earned income: $70000.0 Taxes: $20300.0
Place your solution in a file called "TaxesEarnedIncome.java" and (after testing) submit it below.
If you request solutions for this lab you will be sent an email that contains your answers as well as the expected answers. The email will be sent out to all interested students once the deadline for completing the exercises has passed for all students.