Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
68 views12 pages

COMP1406-W23-T01 Specification

The document provides instructions for completing Tutorial #1 in COMP 1406. It includes 4 problems: 1) Getting started with IntelliJ IDE, 2) Creating a tax calculation program in Java, 3) Completing methods to perform operations on arrays, and 4) Instructions for correctly submitting the tutorial assignment as a zip file in Brightspace. The document emphasizes that submissions must exactly match the specified name and file type or marks will be lost.

Uploaded by

bob hock
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views12 pages

COMP1406-W23-T01 Specification

The document provides instructions for completing Tutorial #1 in COMP 1406. It includes 4 problems: 1) Getting started with IntelliJ IDE, 2) Creating a tax calculation program in Java, 3) Completing methods to perform operations on arrays, and 4) Instructions for correctly submitting the tutorial assignment as a zip file in Brightspace. The document emphasizes that submissions must exactly match the specified name and file type or marks will be lost.

Uploaded by

bob hock
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

COMP 1406 B/C/D


Winter 2023 - Tutorial #1

Objectives
● Write, compile and run simple Java programs using the IntelliJ Idea IDE.
● Practice creating a zip file and submitting to Brightspace
● Practice writing basic Java code
● Practice basic problem solving

Expectations
For each tutorial, you will be graded based on the following scale:
• 3/3 for submitting high quality solutions to all problems
• 2/3 if you are missing problems or your solutions need significant improvement
• 1/3 if you are missing several problems or your solutions are poorly done
• 0/3 if you do not make a submission or your submission cannot be executed

Problem 1 (Getting Started with IntelliJ)

IntelliJ Idea is the IDE (Integrated Development Environment) that


will be used throughout the course. IntelliJ Idea Community
Edition is free and is available for Mac OS, Windows and Linux
operating systems. You should use it to write all of your programs in
this course. You will be saving and zipping the project files to hand
in for ALL of your tutorials and assignments.

Upon starting the IntelliJ IDE, you should see a


window something like what is shown here:

1
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

Once IntelliJ has started, you should see the following. Select "New Project" to
continue.

A dialog box will appear. Select Java in the left side panel. Then select the New ...
button at the top of the window and select JDK in the pop-up menu that appears:

Select the latest JDK installed on your computer, if IntelliJ did not find it automatically,
then press OK.

2
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

A new window will appear. Just click Next.

3
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

Type in a project name. For this tutorial, you can use the name Tutorial1 as the Project name
and then press Finish:

You should see the main workbench window appear, as below.

4
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

Expand the project by clicking the triangle to the left of the Tutorial1 project. Then click the src
folder:

From the File menu, select New and then Java Class.

5
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

Enter HelloWorld as the class name:

You should see a class template similar to the one in the picture below:

6
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

Type in the whole program as shown here:

Right-click on the program panel (i.e., on the panel that contains your code) and select Run
'HelloWorld.main()' from the pop-up menu.

7
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

Your program should now run and the result should appear in the bottom Console pane.

8
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

Problem 2 (Tax Program)


Within the same project, create a class called TaxProgram with the code shown below.
It should compile and run. Currently, the program just asks the user for their taxable
income and then the number of dependents that they have.

import java.util.Scanner;

public class TaxProgram {


public static void main(String args[]) {
double income, fedTax, provTax;
int dependents;

Scanner input = new Scanner(System.in);

System.out.print("Please enter your taxable income: ");


income = input.nextDouble();
System.out.println();

System.out.print("Please enter your number of dependents: ");


dependents = input.nextInt();
System.out.println();

fedTax = 0.0;
provTax = 0.0;

// Add code here


}
}

Making use of the income and fedTax variables in the code, insert code at the end of the
program so that it computes and displays the fedTax using the rules shown below:

• If the income is less than or equal to $29,590, the federal tax should be
17% of the income

• If the income is in the range from $29,590.01 to $59,179.99 then the federal tax
should be:(17% of $29,590 + (26% of (the income minus $29,590))

• If the income is $59,180 or more then the federal tax should be:
(17% of $29,590) + (26% of $29,590) + (29% of (the income minus
$59,180))

Test your code with the following values to make sure that it is correct before you continue:

Income $25,000 $53,000 $65,000


FedTax $4,250 $11,116.90 $14,411.50

9
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

Insert code at the end of the program so that it computes and displays the provincial tax
and finally the total tax using the rules shown below:
• The base provincial tax will be:
42.5% of the federal tax
• The deductions for the provincial tax will be:
$160.50 + $328 per dependent
• The provTax is then calculated as $0 if the base provincial tax is less than the
deductions, otherwise as follows:
base - deductions
• The total tax is the sum of the fedTax and the provTax.
Test your code with the following values to make sure that it is correct:
Income $25,000 $53,000 $65,000
Dependants 1 2 3
FedTax $4,250 $11,116.90 $14,411.50
ProvTax $1,317.75 $3,908.18 $4,980.39
TotalTax $5,567.75 $15,025.08 $19,391.89

Adjust your code above so that it displays with the following output format by using
System.out.println() statements as well as String.format() (see Chapter 1 of Mark
Lanthier’s notes for details on String.format()):
Please enter your taxable income: 25000
Please enter your number of dependents: 1

Here is your tax breakdown:

Income $25,000.00
Dependants 1
----------------------------
Federal Tax $4,250.00
Provincial Tax $1,317.75
============================
Total Tax $5,567.75

Problem 3 (Arrays and Problem Solving)


Download and open the ArrayPractice.java file from the tutorial #1 page on Brightspace.
The main method of this Java file creates several arrays and calls several methods to
perform operations on those arrays. You must write the implementation for each of the
five methods so that the correct values are returned. A description of each method is
included in comments within the file. Note that the merge method and the
longestIncreasingSequence method are moderately difficult problems. If you can solve
each of these on your own, you should be in a good position going forward in the

10
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

course. Remember to break the problem down and identify what information/variables
you need to solve the problem. If you are completely stuck on either of these methods,
check the end of the tutorial document for some hints (try to use as few hints as
possible).

Problem 4 (Submitting in Brightspace)


In this course all assignment submissions, unless otherwise stated, will be a single zip
file containing a complete IntelliJ project – this makes it easier for the TAs to compile
and execute your code. You must be extremely careful with the details of your
submissions.

For example, when you are asked to submit an assignment called assignment2.zip,
your submission will lose marks if the filename is not exactly as specified. If you submit
Assignment2.zip, assignment02.zip, MyAssignment2.zip, a2.zip, or anything that
is not exactly assignment2.zip, you will lose marks. Please note that case matters.
A and a are not the same!

When you are asked to submit a zip file, you must submit a zip file. This means that if
you use 7zip, rar or any other programs to create a compressed archive of your files
that is not a zip file, you will lose marks.

The IntelliJ IDE has built-in functionality to save your project as a zip. While your project
is open in IntelliJ, go to the File menu, then the Export sub-menu, and then select
Project to Zip File… Save the zip file as tutorial1.zip.

Submit your tutorial1.zip file to the tutorial drop box on Brightspace. After you submit the
file, download your submission from Brightspace and confirm that it is a zip file called
tutorial1.zip. Extract the contents of the zip and try opening the folder as a project in
IntelliJ (File à Open, then select the folder that was contained in the zip). Occasionally,
there can be a problem during the upload process and files can become corrupted.
Downloading, verifying, and executing your submissions ensures that the files
were uploaded correctly. Assignment submissions that are corrupted or missing
files will be penalized – make sure that you double-check your submissions. If you
are unsure whether your submission was uploaded correctly, stop by office hours and
ask a TA to double-check the submission for you.

Problem 3 Merge Hints


1) The size of the result array must be equal to the sum of the sizes of a and b. Use
the length property of Java arrays.

11
COMP 1406 B/C/D – Winter 2023 – Tutorial #1 Due Friday, January 20th, 11:59pm

2) As both argument arrays are sorted in increasing order, the problem can be
solved by repeatedly copying the next largest item that has not been copied yet
from a or b into the proper place in the resulting array.
3) To do this, you can use three index values: current index in a, current index in b,
current index in result. As you copy items into the result array, you increase the
associated index. As you copy items from a or b, you increase their respective
index (basically, moving to the next item in the array).
4) At any point, you have three possible cases: a has been copied completely, b
has been copied completely, a and b both have elements left to copy.
5) If a has been copied completely, you need to copy the next element from b (and
vice versa). If neither have been copied completely, you need to compare the
current elements of each and take the lowest one.

Problem 3 Sequence Hints


1) You need to keep track of the longest sequence you have found while iterating
over the array.
2) The first element in the array is automatically considered increasing (there are no
preceding elements).
3) Each successive item in the list either continues the previous increasing
sequence (i.e., is larger than the number before it), or starts a new sequence.
4) You will need a variable to keep track of how long the current sequence is.
5) Any time a sequence ends (and when you reach the end of the array), you must
compare your sequence length to the longest length and possibly update the
longest sequence variable.
6) Once a sequence ends, you start over at the current element. Remember to
count the current element as part of the new sequence.

12

You might also like