## Random Circles

Create an interactive Processing program that creates 20 random circles and allows the user to select one at a time. If
the user selects a circle, it turns green. If the user presses the ‘+’ or ‘-‘ keys after selecting a circle, the circle increases or
decreases in size. If the user presses the ‘w’, ‘a’, ‘s’, or ‘d’ keys after selecting the circle, the circle moves up, left, down,
or right.
Program Behaviour:
 Use a 600×600 canvas
 Create 20 circles and store information about the circles using a global list of records
o Circles should initially be given random locations (the centre of the circle should be within the bounds of
the canvas) and should initially be given a random diameter that is between 20 and 50 pixels.
o Give each circle a unique ID number: the first circle should have ID 1 and the last circle should have ID 20
 If the user clicks on a circle, store that circle’s ID number in a global variable to indicate which circle is selected
o If the user clicks but their cursor is not inside any circle, the ‘selected’ variable should be set to 0 to
indicate that no circle is selected
 Draw all of the circles on a black background
o If a circle is selected (based on its ID number), fill the circle with green; otherwise, fill the circle with grey
 The following keypresses will change the selected circle (and will do nothing if there is no selected circle):
o If the user presses ‘+’, increase the diameter of the selected circle by 1
o If the user presses ‘-‘, decrease the diameter of the selected circle by 1 (with a minimum of 20)
o If the user presses ‘w’, move the selected circle up by 1
o If the user presses ‘s’, move the selected circle down by 1
o If the user presses ‘a’, move the selected circle left by 1
o If the user presses ‘d’, move the selected circle right by 1

## Hourglass

Write a Java program to draw an ASCII hourglass image using just nested for loops, a global constant, static methods, and print/println statements. I got a response earlier but realized that the help I got used “repeat()”, “.append”, etc. which we haven’t learned yet. I’ve rewritten my code to fit the assignment requirements and am still receiving error codes. Not sure how to fix this using nested for loops.

## Encrypt

A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four-digit integers. They have asked you to write a program that will encrypt their data so that it may be transmitted more securely.
Your program should read a four-digit integer and encrypt it as follows: Replace each digit by the remainder after the sum of that digit plus 7 is divided by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. Write a separate program that will encrypt a four-digit integer and decrypt it to form the original number. You can use ‘0000’ to terminate the program.

## Chpt8_Project

Write a Java program that stores the names of two cites in a single dimension array, and their latitude and longitude in a two-dimension array. Next calculate the distance between the city in miles and display.

Inputs: The names of two cities and their latitudes and longitudes.

Enter the first city:
Enter the second city:
Enter latitude and longitude of first city separated by a space (example 28.8 81.2):
Enter latitude and longitude of second city separated by a space (example 28.8 81.2):

The city names should be stored in a single dimension array that stores strings, and the latitudes and longitudes for each city should be stored as doubles in a two-dimension array.

Outputs: The distance between the two cities in miles, note: replace <> with the distance calculated

The distance between the two cities is <> miles

## TV Shows

Write a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. The input file contains an unsorted list of number of seasons followed by the corresponding TV show. Your program should put the contents of the input file into a dictionary where the number of seasons are the keys, and a list of TV shows are the values (since multiple shows could have the same number of seasons).Sort the dictionary by key (least to greatest) and output the results to a file named output_keys.txt, separating multiple TV shows associated with the same key with a semicolon (;). Next, sort the dictionary by values (alphabetical order), and output the results to a file named output_titles.txt.Ex: If the input is:file1.txt
and the contents of file1.txt are:20
Gunsmoke
30
The Simpsons
10
Will & Grace
14
Dallas
20
Law & Order
12
Murder, She Wrote
the file output_keys.txt should contain:10: Will & Grace
12: Murder, She Wrote
14: Dallas
20: Gunsmoke; Law & Order
30: The Simpsons
and the file output_titles.txt should contain:Dallas
Gunsmoke
Law & Order
Murder, She Wrote
The Simpsons
Will & Grace

## Rational

Modify the rational number class. Represent rational numbers as two values of type int,
one for the numerator and one for the denominator.
Include a constructor with two arguments that can be used to set the member variables of
an object to any legitimate values. Also include a constructor that has only a single parameter
of type int; call this single parameter whole_number and define the constructor so that
the object will be initialized to the rational number whole_number/1. Also include a
default constructor that initializes an object to 0 (that is, to 0/1).
Overload the input and output operators >> and <<. Numbers are to be input and output in the form 1/2, 15/32, 300/401, and so forth. Note that the numerator, the denominator, or both may contain a minus sign, so -1/2, 15/32, and -300/-401 are also possible inputs. Overload all of the following operators so that they correctly apply to the type Rational: ==, <, <=, >, >=, +, -, *, and /. Also overload the unary -.
Use the same formulas as assignment 8 for defining the overloaded operators. Makes use of
overloaded operators should return a bool value.
Provide a main function that thoroughly tests your class implementation. Create two
objects (each representing a rational number). Test the two objects with each of the
overloaded functions. Also test the operators with a combination of integers and objects.

## DiaryEntry

You are to implement a class to define the type “DiaryEntry”. The interface of the class along with the description of its members is given in the file “DiaryEntry.h” attached to this question. Based on the description of the class, implement the methods of the class, and test your class using the attached cpp file: “DiaryTest.cpp”.

## AreaRectangle

Write a program that calculates the area and perimeter of a rectangle. The side lengths should be inputted by the
user. The area and perimeter of the rectangle should be calculated and returned using 2 user defined functions; area &
perimeter and then outputted as shown below. Note that 5.6 and9.8 are only examples.
A 5.6 by 9.8 rectangle has an area of 54.88 and a perimeter of 30.8.

In this section, you will create a new Console Project which contains a Transaction class
and a TransactionMode enumeration.
Each Transaction will:
■ Know its transaction number
■ Know its date
■ Know its amounts
■ Know its points gained
■ Know what transaction mode it belongs
■ Can be constructed with a given transaction number, date, amounts, and transaction
mode
■ Can update the points based on the transaction amount (For every transaction amount
of RM10 is equivalent to 1 point)
■ Can be printed, which returns a message depending on the transaction mode.
These are the following Transaction Mode, and they return the indicated messages:
■ Online
o “That’s a wise choice with more rewards”
■ Offline
o “You have secured some points”

## Loop Programs

Directions:
For each problem an output is given to you, as well as a skeleton code. You need to decide what needs to go in place for every “#” you see in the skeleton code to produce the output. You ONLY need to change the “#’s.”
Problem Output Code Skeleton
a) for # in range(#,#):
for # in range(#, #):
print( # ,””,end=”)
print(“\n”)
b) for # in range(#,#):
for # in range(#,#):
print(#,””,end=”)
print(“\n”)
c) for # in range(#,#,#):
for # in range(#,#,#):
print(#*#,””,end=”)
print(“\n”)
d) for # in range(#,#,#):
for # in range(#,#,#):
if #==#:
print(“#”,””,end=”)
else:
print(“#”,””,end=”)
print(“\n”)
e) for # in range(#,#,#):
for # in range(#,#,#):
if #==1 or #==4 or #==1 or #==4:
print(“#,””,end=”)
else:
print(“#”,””,end=”)
print(“\n”)

×