Course Hero Logo
Question
Answered step-by-step

Computers are a great help in science, especially with tedious...

Computers are a great help in science, especially with tedious activities. Write a program to determine differences in DNA sequences of base pairs, which are described with the letters: A, G, C, T (https://ghr.nlm.nih.gov/primer/basics/dna)

The applications reads in records from a file, with each record having: a record number, and two strings. This describes the ing DNA sequences to be compared, with at least 8 letters (upper or lowercase), with the same number of symbols in both strings.

An example of a record in the file, showing record # 5 and its set of DNA sequence strings: 3 AaacaacttcGTAAGTATA AAGTTCCTtcgtaagTATA

Note: You are not verifying the biological correctness of the DNA base pairs, but simple treating them characters.

Part 1: The DNA sequence sets are read from a file, with the filename prompted & input from the user (see DNA.txt file). Create your own file, that has one or two records, to make development & testing easier.

Iterate to process all the records from the file, that have: # record number, DNA sequence 1, DAN sequence string 2

Rules for processing the DNA sequence sets:

- if the two sequences have different lengths or either has less than 8 chars, the comparison is incomplete. For this record, the result is: "Sequence must be longer" or "Sequences must be the same length" and proceeds to the next record. Assume all letters in the sequences are correct (that sequence characters are correctly A, G, C, or T.)

- if there are no errors, loop through the strings, comparing the DNA letter pairs at each position in the both sequences and

display a table for the DNA record: = (letters are the same) or ! (not the same) - example:

Part 2: Below each table, the program displays a summary,

• the length of the sequences, for example:

DNA Sequence length: 19

• count of the number of differences, for example:

There are 4 differences between the sequences.

or:

There are no differences, sequences are a match.

Part 3: ,

- along with prompting the user for the input file, also prompt for an output report file; change from displaying the report to the console to sending to the report file

HINTS:

- recall the String class methods: .charAt(), .toUpperCase(), .substring(), .length(), etc.

- recall the Scanner class methods: .next(), .nextInt(), and others

- how to open a file and process an input ( .hasNext(), and send to output files (PrintWriter)

- to help line up the data in the table, consider using String.format() or .printf() when sending to output

o example: String.format ("%4d: %c %c %c", pos, char1, symbol, char2) which right-justifies int pos in a width of 4, and displays chars char1, symbol, and char2

- write any methods you think may help simplify the main() method and make the program more efficient

Submission: A single application submission, with input data file(s) and associated output captures, for however many parts above are completed. If the solution is generating results to a report file, include all files that match what is shown in the output capture.

Note: If the all the program displays to the console are the prompt for input & output filenames, don't forget to capture this as part of a run.

Record ##:

Pos: S1 - S2

1: A = A

2: A = A

3: A ! G

4: C ! T

5: A ! T

6: A ! C

7: C = C

8: T = T

...

18: T = T

19: A = A

4

[8 marks] Question 3 Extend the "random direction" concept from a previous assignment, in a random direction is chosen to move: U, D, L, or R (for up, down, left, or right). In a new application, the goal is to have the character move in a random direction, along with some rules and a distance feature. The application must, - ask the user for the number of "moves" (iterations, loops) for the character - for each iteration, the computer picks a new random direction, one of: U, D, L, or R Rule: o if the random direction is "opposite" of the last direction, then pick a new random direction ▪ opposite of UP is DOWN, opposite of DOWN is UP ▪ opposite of LEFT is RIGHT, opposite of RIGHT is LEFT ▪ this prevents the character from moving in place and wasting an iteration undoing the previous move o consider, ▪ putting the random direction pick in an inner loop, picking a new random value valid; OR ▪ if an opposite direction is chosen, don't count the iteration and don't display anything o along with a variable for the new direction, a variable is needed for the last direction ▪ initialise the last direction as UP ▪ set the last direction to the new direction after a valid new direction is picked o only valid moves are counted as iterations and only valid moves are displayed - pick a random distance, from 0 to 10 units (11 possible values) - display result: "Moved: M for DD units" (where M is U, D, L, or R direction; and DD is the distance) - after all iterations are complete, a "total distance" travelled is displayed Example, with user input in highlight: Run the program, and capture output, with testing that shows - all movement directions are possible (U, D, L, R), and - opposite directions sequences are not chosen and not displayed (for example: a sequence not show moving Left followed by moving Right) - along with short iterations (to ensure the directions and total distance are calculated properly), consider some long runs to really test the "don't pick opposite direction" logic is working (20, 50, 100 iterations)

Submission:

- include your complete solution and output captures of running the application

How many moves? 8

#1: Moved: U for 2 units

#2: Moved: R for 0 units

#3: Moved: R for 8 units

#4: Moved: D for 8 units

#5: Moved: L for 10 units

#6: Moved: U for 2 units

#7: Moved: R for 3 units

#8: Moved: U for 1 units

Total distance: 34

Answer & Explanation
Verified Solved by verified expert

facilisis. Pellentesque dapi

ec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lore

Unlock full access to Course Hero

Explore over 16 million step-by-step answers from our library

Subscribe to view answer
Step-by-step explanation

itur laoreet. Nam
rem ipsum dolor sit
nec facilisis. Pellentes

lestie consequat, ultri
o
ac, dictum vitae odio. Donec a
ec aliquet. Lorem ipsum
llentesque dapibus effici
itur laoreet. Nam risus ante, dapi
ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, d
sus ante, dapibus a molestie consequat, ultrices ac magna. Fusc

sque dapibus efficitur laoreet. Nam risu
sum do
sque dapibus efficitur laoreet. Nam risus ante,
dictum vitae odio. Done
ec aliquet. Lorem ipsum
Donec

facilisis. Pellentesque dapibus efficitur laoreet. Na
sum do
sque dapibus efficitur laoreet. Nam risus ante,
facilisis. Pellentesque da
ec aliquet. Lorem ipsum
Donec

ipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesq
sum do
sque dapibus efficitur laoreet. Nam risus ante,
facilisis. Pellentesque da
ur laoreet. Nam risus ante,
Donec

icitur laoreet. Nam risu
sum do
or nec facilisis. Pellentesque dap
Donec

usce dui lectus, congue vel
sum do
facilisis. Pellentesque d
Donec

s a molestie consequat, ultr
sum do
at, ultrices ac magna. Fus
Donec

entesque dapibus efficitur la
sum do
llentesque dapibus effici
Donec

or nec facilisis. Pellentesque dapi
sum do
entesque dapibus efficitur laoreet. Nam

sque dapibus efficitur laoreet
at, ultrices ac
cing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet
Fusce dui lectus, congue vel lao
entesque dapibu

s a molestie consequat, ultrices ac magna. Fusc
s ante, dapibus a molestie consequat, ult
molestie consequat, ultrices
at, ultrices ac
, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur
Fusce dui lectus, congue vel lao
entesque dapibu
trices ac magna. F
at, ultrices ac
ce dui lectus, congue vel laoree
entesque dapibu
Donec

or nec
iscing elit. Nam lacinia pulvinar
facilisis. Pellentesque dapibus efficitur laoreet. Nam
ia pulvinar tortor nec facilisis
sum do
cing elit. Nam lacinia p
entesque dapibus efficitur laoreet. Nam
sque dapibus efficitur laoreet
sque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac mag
Fusce dui lectus, congue vel lao
entesque dapibu
Donec aliquet. Lorem ipsum dolo
at, ultrices ac
or nec facilisis. Pellentesque dapibus efficitur laoreet.
at, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem
a. Fusce dui lectus, congue vel l
m ipsum dolor sit ame
cing elit. Nam lacinia p
amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie
ongue vel laoreet ac, dictum vitae odio.
m ipsum dolor sit ame
entesque dapibu
, dictum vitae odio. Donec
Donec
dictum

itur laoreet. Nam risus ante, da
inia pulvinar tortor nec fac
Donec


nec facilisis. Pellentesque dapibus efficitur laoreet.
sum do
sus ante, dapibus a molestie consequat, ultrices ac magna
Donec

inia pulvinar tortor nec facil
sum do
ac, dictum vitae odio. Donec aliquet.
Donec

ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pul
sum do
acinia pulvinar tortor nec facilisis. Pel
or nec facilisis. Pellentesque dapibu

sus ante, dapibus a molestie consequat, ultrices
at, ultrices ac
, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet,
nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibu
entesque dapibu

cing elit. Nam lacinia pulvinar tortor nec fa
at, ultrices ac
lestie consequat, ultrices ac magna. Fusce dui lectus, con
e vel laoreet ac, dic
dictum vitae odio. Donec aliquet. Lorem ipsum d
m ipsum dolor sit ame
entesque dapibu

sus ante, dapibus a molestie consequa
Donec


iscing elit. Nam lacinia pulvinar to
nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultric
iscing elit. Nam lacinia pulvinar to
, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, con
sum do
nec facilisis. Pellentesque dapib
rem ipsum dolor sit amet, consectetur adipisc
ce dui lectus, congue vel laoreet ac, dictum
molestie consequat, ultrices ac magna. Fusce dui lec
amet, consectetur adipiscing elit. Nam lacinia pulvi
nec facilisis. Pellentesque dapibus efficitur la
gue vel laoreet ac, dictum vitae odio. Donec aliq
fficitur laoreet. Nam risus ante,

sque dapibus efficitur
itur laoreet. Nam risus ante,
ec aliquet. Lorem ipsum dolor
sum dolor sit amet, consect
usce dui lectus, congue vel
entesque dapibu
usce dui lectus, congue vel
, consectetur adipiscing elit
entesque dapibu
a molestie consequat, ultrices ac ma

ur laoreet. Nam risus a
nec facilisis. Pellentesque dapibus ef
s ante, dapibus a molestie conse
entesque dapibu

usce dui lectus, congue vel laoreet ac,
nec facilisis. Pellentesque dap
entesque dapibu

sum dolor sit amet, con
ur laoreet. Nam risus ante, dapibus a mo

fficitur laoreet. Nam risus ante, dapibus a

ia pulvinar tortor nec facili
sum dolor sit amet, consectetur adipiscing eli

Fusce dui lectus, congue vel laoreet ac, dictum vit

ipsum dolor sit amet, consectetur adi
cing elit. Nam lacinia pulvinar tortor nec fac
, dictum vitae odio. Donec aliquet. Lorem ip
ce dui lectus, congue vel laor
facilisis. Pellentesque dapibus ef
ipsum dolor sit amet, consectetur adipiscing
ce dui lectus, congue vel laor

risus ante, dapibus a molestie conse
Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar

m ipsum dolor sit ame

entesque dapibu

ipsum dolor sit amet,
risus ante, dapibus a molesti

Donec


ce dui lectus, congue vel laoreet ac, dictum vitae odio. Don
at, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dict
ng elit. Nam lacinia pulvinar tortor nec
at, ultrices ac
et, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellent
entesque dapibu
gue

Student review
100% (1 rating)