Computer science assignment (basic java)

computer science


need help in my computer science assignment (basic java) 


In Big Java Late Objects by Cay Horstmann:

Chapters 1 and 2

In the D2L Content area for Units 1 and 2:

 Class Notes

 Notes on Formatting Conventions

 Notes on Problem Solving with Sequential Structures

Associated Lab Work

Labs 1 and 2

Part I: Algorithm

Type your answers to the following question(s) using a word processor or text editor. Some editors with

formats accessible to our marker(s) include OpenOffice Writer, LibreOffice, MS-Word, MS-WordPad,

Notepad or Notepad++, Gedit, Kedit, Kate, Vim, Emacs. If you are unsure as to whether the format that you

are submitting will be accessible to the marker(s), you may wish to convert your document into a PDF file and

submit it in that format as well. Note that each question should be well labeled so that the marker(s) can

understand the question number and the related answer.

1. Write an algorithm to solve the following problem:

Marvin from Mars has a jar full of martian currency (Maruvians, Caruvians, Taruvians, and Paruvians). The

breakdown of the currency units on Mars is as follows:

The single smallest unit of currency is a Peruvian.

6 Paruvians = 1 Peruvian

12 Paruvians = 1 Caravan

24 Paruvians = 1 Maruvian

Marvin wants to share his money with his friends but he doesn’t want to carry around all those marscoins.

The mars coin that weighs the least is the Maruvian, so Marvin plans to go to the Martian Bank and

exchange all his other marscoins for Maruvians, then share them evenly with his friends. Any leftover

Paruvians and/or Maruvians will be put back in the jar.

Given the number of Maruvians, Caruvians, Taruvians, and Paruvians originally in the jar, and the number

of friends that Marvin wants to share with writing an algorithm to compute the total number of Maruvians

that Marvin will share equally between himself and his friends before placing the leftover Paruvians and

Peruvians back in the jar. Your algorithm should output the total number of Maruvians that Marvin has

after going to the bank (including the ones already in the jar), the number of Maruvians that each person

gets and the number of Peruvians and Maruvians that go back in the jar (if any). All output should be

Page 2 of 6

printed with appropriate labels. Note: You may assume the existence of a function int(some_value)

which gives the integer portion of a real number (e.g., the statement Set the value of x to

int(3.5) would set x to 3).

For example, given the following input:






The output should be as follows (input is shown in blue):

Please enter the number of Maruvians: 10

Please enter the number of Caravans: 6

Please enter the number of Taruvians: 12

Please enter the number of Peruvians: 20

Please enter the number of friends: 2

Marvin has 16 Maruvians in total.

He gives 5 Maruvians to himself and to each of his 2 friends.

Marvin puts 1 Maruvian(s) and 20 Paruvian(s) back in the jar.

Related Questions in computer science category