PassTask3

Downloads 1

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

Downloads 2

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”)

FileProg

Downloads 3

Write a while loop that continues to ask a user to enter the file name they want to read if they do not enter the write format for example the program should not “crash” if the user enters a bad filename (a file that does not exist).
Instead, it should start over asking the user for the filename. If common.txt is not present,
the code should work without it.

EmailDirectory

Downloads 4

Write a program that keeps names and email addresses in a dictionary as key-value pairs.
The program should display a menu that lets the user look up a person’s email address, add a new name and email address, change an existing email address, and delete an existing name and email address. The program should save the data stored in a dictionary to a file when the user exits the program. Each time the program starts, it should retrieve the data from the file and store it in a dictionary.

You must create and use at least 5 meaningful functions.
• A function to display a menu
• A function to look up a person’s email address
• A function to add a new name and email address
• A function to change an email address
• A function to delete a name and email address.

Your program should check user input; for example, if the user wants to delete a name that does not exist in the dictionary, you should print something like: the name is not in the database. A sample one run is shown below.

TemperatureNurse

Downloads 5

Write a Java program that does the following:
1. In the main() method complete the following:
1. Ask user to enter number of days that was patient entered to the hospital ( i.e 5 days)
2. Enter number of times that nurse read the temperature of patient in Celsius (3,4, 5, time or even more) 4. Within the loop, ask the user to enter temperature were read by nurse. 5. Within the loop, store each temperature in your array. 6. If the user enters a temperature below 33.5C or above 42C, then display an error message and keep looping till read the right one.
2. Write just one method call it Summary that called from main method and return average,maximum, and minimum of temperatures. Print the result on screen from main method.
3. Call another method call it belowAboveAverage that will return number of temperatures less than or equal to average of temperatures, and number of temperatures above the average.
4. Call a method sorting call it sortedArray that will sort using binary the temperatures in ascending order during all days store it in new 2D dimensional array and return it to main. 5. Call printArray method to print the sorted array on screen.
Sample:
Days #of Readings Actual Reading Per Day (in Celsius ) 1 4 40.5 41 39.8 38.7 2 5 41.2 41.3 40.7 40.8 41.3 3 5 40.9 38.5 38.9 40.1 39.8 4 3 38.2 38.2 37.9 5 2 37.5 37.2

PairWise

Downloads 6

In this exercise, we are looking for all pairwise multiplications between numbers from a
given list of numbers. In particular, you are given a list of integers. We are then looking
for possible multiplications that can be created by pairs of two out of the given
numbers. For example, when the input list contains the numbers 1, 2 and 3, then the
pairwise multiplications are 2 (1*2 ), 3 ( 1*3 ) and 6 (2*3 ). The found pairwise
multiplications have to be returned in a list.Your program should:
– Take as input a List of numbers
– Return all pairwise multiplications as a List
– Have the following signature:
public static List getPairwiseMultiplications(List
numbers)Moreover, take into account the following when writing your program:
– Each pairwise multiplication of two numbers in the list should be included only
once in the returned list.
– If two pairs of numbers have the same pairwise multiplication, you should include
only one result. For example, when the numbers 2, 3, 4 and 6 are all included in
the input list, then both 2*6 and 3*4 result in 12. However, 12 should be included
only once in the output.
– Your program should be able to handle a list of all sizes as input, even an empty
list or a list with one element. In both these cases, it should return an empty list.
– The order of elements in the output lists is not important, so you can have an
output that contains the same elements but in a different order.
– You can assume that all multiplications can fit into a variable of the int type.

LowerUpperBound

Downloads 7

Prompts the user to input the lower bound and upper bound. Include input validation to ensure that the lower bound is less than the upperbound.
-Generates a random number between the lower and upper bounds
-Prompts the user to input a guess between the lower and upper bounds. Include input validation to ensure that the user only enters values between the lower and upper bound.
-Prints an output statement based on the guessed number. Be sure to account for each of the following situations through the use of decision branching:
What should the computer output if the user guesses a number that is too low?
What should the computer output if the user guesses a number that is too high?
What should the computer output if the user guesses the right number?
-Loops so that the game continues prompting the user for a new number until the user guesses the correc

SineCosine

Downloads 8

The exponential, sine, and cosine series function are as follows:
e
x =
P∞
n=0
x
n
n!
sin x =
P∞
n=0
(−1)nx
2n+1
(2n+1)!
cos x =
P∞
n=0
(−1)nx
2n
(2n)!
a. Write a C++ program that calculates the series e
x
, sin x and cos x, where the user enters value
of x and the n the number of terms in the series. (Note: you may have to convert degrees to
radians for sin and cos functions). Note that the program should use functions for each of
the series. 12 Points
b. Draw a detailed flow chart on how this program is being designed, indicating the necessary inputs,
outputs and the algorithm you have used. The flow chart should be included as a document file
along with your program listing (source code). 4 Points
c. Now do a convergence study using different values of n for a given value of x and plot the
convergence graph.

FileNumberAddition

Downloads 9

Write a program to input text from a file and output the total of all the “numbers” in the file. A
number will be any sequence of digits followed by a “non-digit” (a period or a comma are nondigits too). For instance, “3.14159” in the file would be counted as two numbers to add to the
total: a 3 and 14159; “21,756.54” would add three numbers to the total: 21, 756 and 54.
Numbers will not be split over 2 lines.
Here is the precise dialog required:
Program to count the total
of the numbers in a file.
You will be asked to enter
the name of a file.
Written by Name.
Enter the name of a file to count: mywords.txt
The original file
mywords.txt
has been counted and the sum of
all numbers is 1380

Chpt5_Project

Downloads 10

Write a Java program that generates 100 random numbers in the range of 0-100 and counts how many are equal to or greater than a value entered by the user.

Inputs: Prompt the user for the value to test against. This value must be between 30 and 70. If the value is out of range then let the user reenter the value until it is with the range.

Outputs: The output will be all the number of random numbers equal to or larger than the number input by the user.

Step 1. Create an algorithm (either flowchart or pseudocode) that you will use to write the program. Place the algorithm in a Word document.
Step 2. Code the program to prompt the user for a value between 30 and 70 (30 < value < 70). The value must the checked to ensure it is in the required range. If the user’s value is out of range then they are prompted to reenter until the value is in range. Use a while or do-while loop to keep prompting until the value is within the range. Next, use a for loop to generate 100 random variables between 0 and 100 and compare each random number to the value entered by the user. If value < random number then then increase the count by 1. Lastly, print out the number of times the random number is larger than the value entered by the user. Step 3. Test your program and it should display the number of random numbers greater than or equal to the user input value. Use the test data in the example below by entering 80 first, which is out of range, then enter 50. Note: the number of random variables greater than 50 will vary because the user value is being compared to random numbers, and those random numbers change each time the program runs. Use the Snip It tool in Windows or a similar tool on the Mac to cut and paste the Eclipse Console output window into the same Word document as the algorithm in Step 1. Below is an example output. Note: your output will be different because random numbers are involved.

×
New Download