0% found this document useful (0 votes)
6 views3 pages

Tutorial 01

This document is a tutorial for CS101, providing exercises to enhance programming skills. It includes tasks such as creating a grade calculator, debugging Java code, preparing an HTML Tinder profile, writing pseudo code for a prime number program, and a bonus exercise on swapping integer values without a third variable. The tutorial emphasizes the importance of organizing project files and offers useful resources for assistance.

Uploaded by

anilaltuncu771
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)
6 views3 pages

Tutorial 01

This document is a tutorial for CS101, providing exercises to enhance programming skills. It includes tasks such as creating a grade calculator, debugging Java code, preparing an HTML Tinder profile, writing pseudo code for a prime number program, and a bonus exercise on swapping integer values without a third variable. The tutorial emphasizes the importance of organizing project files and offers useful resources for assistance.

Uploaded by

anilaltuncu771
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/ 3

TUTORIAL #1

Welcome to CS101 tutorials! The following exercises are prepared to strengthen the skills you
have gained in the previous CS101 lab assignments. Hope it will be helpful. Since these
exercises are meant to develop your programming skills, you are free to choose the exercises that
you feel would be beneficial for you.
I put some useful links here that you might seek help from throughout these exercises.
David’s templates: cs101_template.txt
CS101 guidelines:
http://www.cs.bilkent.edu.tr/~david/cs101/practicalwork/styleguidelines.htm
CS101 Lab02: http://cs.bilkent.edu.tr/~david/cs101/assignments/lab02/
Preparation:
Create a new folder named “tutorial01” in your H: drive. Open DrJava and create a new project
inside that folder for each exercise that you will do, named accordingly.
While creating a new project, please remember to create a new folder named “TutorialOneA”
inside “tutorial01” as well as writing “TutotialOneA” to the file name. The first will create the
folder which will include all ‘.java’, ‘.drjava’ and ‘.class’ files. The second will be the name of
the ‘.drjava’ file. Arranging documents are quite important so please pay attention to properly
preparing your documents for usage.
Exercises:
a) Grade Calculator
In this exercise, you will code your own grade calculator! Classes might have lots of confusing
different criteria and percentages that affect your total grade of the class. So, a program to collect
all your grades and calculates your final grade might come in handy. :) I will use CS101
assessment methods for this exercise but please feel free to adapt new courses’ grading methods,
too.
Criteria Total Contribution
Final 30
Midterm 30
Homework 5
Quiz 10
Lab Exam 25

Step 1: Please copy-paste David’s “simple console application” syntax from the cs101 template
file. Fill in the information in the header comment. Change the class name to “GradeCalculator”
(from “XXXX”). Save and Compile Project.
Step 2: Decide on how many variables you will need during calculation and their respective
types. Don’t forget about the output which will be your total grade. Declare your variables under
the “//variables” comment. (Tip: You can make the total distribution numbers as constants!)
Step 3: Inside the program code, please ask the user to enter all needed variables (inputs) from
the console and save those entered values inside your pre-declared variables.
Step 4: Print out your minimum and maximum scores from all assessments using Math.min() and
Math.max(). Try to find the optimal way to find a min or max value of 5 different values.
Step 5: Calculate your total course grade with the given contribution percentages and reveal your
answer to the user in the console (print out your result).
Voila! Your grade calculator is ready. Furthermore, if you would like to you are free to output
your results in a HTML format and create a web link.
b) Guess the Output
This exercise is aimed at making you familiar with Java syntax and errors. There are some code
pieces below this question. Please examine them and write the output of the programs. Please
note that if there is a compile-time error or run-time error, you are expected to find and correct
them. You may test your results in DrJava, if you are not certain of the answer.
1. 3.

System.out.print("Hell")
Double a = 25;
System.out.println("o World!");
Int b = 10.5;
System.out.println("Hello”, “nice to meet you.”);
Int result = a / b;
2. System.out.print(“25 divided by 10 is: ” + result);

System.out.println("3 + 4 = " + 3 + 4); 4.


System.out.println("21 / 3 = " + 21 / 3);
string name = Elif;
System.out.println(1 / 0);
System.out.print(name);

c) HTML Tinder
In this exercise, you will be preparing a Tinder (dating application) profile of yourself in HTML.
This exercise will be very similar to the one in Lab02e, so you are free to seek help from David’s
lab assignment link above.
Please create a new project and class with the name “TinderHTML”. If you have problems at this
step, please refer to the preparation stage of this tutorial and/or David’s help in the lab02
assignment.
Your profile will include 4 main criteria for now: name, age, place of study/work, comments.
You are free to be interesting and funny in the comments section.
Step 1: Set up your “TinderHTML” class with cs101 guidelines. Decide on the variables you will
ask for your profile and their types. Declare these variables under the “//variables” section.
Step 2: In the program code, ask the user to get the information for your four sections using the
console in DrJava. Make sure everything is working correctly on the console. Then, print out the
information in HTML format:

<!DOCTYPE html>

<html>

<head>

<title>Elif's Tinder Profile</title>

</head>

<body>

<hr>

<h1>Elif, 19</h1>

<p>Place of study: Bilkent University</p>

<p>Comments: I like Netflix and eating.</p>

<hr>

</body>

</html>

Step 3: Take the inputs from command prompt and generate an “.htm” file of your profile. Since
this step is the exact same as Lab02e. Please refer to the Lab02e’s link above if you need any
support.
d) Pseudo Code
Write a pseudo code describing how you would you design a program that finds out if a given
number is prime. If it is not, the program should print out its dividers.
e) Bonus Exercise: Swap Master
This exercise is a brain teaser. The goal is to try to find a way to swap the values of two integer
variables without using another variable. For example, if a = 10 and b = 20, how do you get b =
10 and a = 20 without using a different variable?
By Elif Kurtay

You might also like