Вы находитесь на странице: 1из 3

IS 2031: LE 6.

2
Sections Lab Day DUE DATE
007 R 4/11/19

Purpose: To learn how to create, populate, and access arrays using value-
receiving and value-returning methods.

Prep Work: Chapter 6 on arrays and Shepherd's chapter 6 PowerPoint


slides.

Lab Exercise 6.2 Instructions: Code a program that prompts the user for
the size of the array. Using the size, the program creates several arrays that
will store information about inventors and their inventions. There will be one
array for the inventor, another for the invention, and the last one for the year
of the invention. The values in each array at the same location are for a given
inventor. Once the arrays are populated, print the information from each
array. The size and input will be the only global variables. Use
printf(). Code your program according to the specifications below. Use the
looping structure generally associated with array processing. Name the
program YourLastNameFirstInitialLE62.java. The methods will be called from
the main().

1st Input Prompt: Code this in a method named arraySize().

How many inventors?

2nd Input Prompt: In a method named setInventors declare the inventors


array and populate it. This method will return the inventors array to the calling
statement. The 9 in the prompt below will print 1 for the first inventor, then 2
for the 2nd one and so forth. Use the loop-control variable as the value for 9.

Enter inventor #9:

3rd Input Prompt: In a method named setInventions declare the inventions


array and populate it. The Xs in the prompt is the inventor. The setInventions
method will return the inventions array to the calling statement as well as
receive the inventors array from the calling statement.

Enter Xxxxxxxxxx's invention:

4th Input Prompt: In a method named setInventionYear declare the year

© Linda Shepherd: LE 1
© https://science.howstuffworks.com/innovation/famous-inventors: Search by inventor.
array and populate it. The Xs in the prompt is the invention. The
setInventionYear method will return the year array to the calling statement as
well as receive the invention array from the calling statement. This method
will be called as an argument in the call to printInventions(). NOTE: The
invention in the prompt is ALL lowercase.

Enter the year in which the xxxxxxxxxxxx was invented:

Output Specifications: Where the Xs represent the inventor and invention and
the Zs the year. Code the output print statement in a method named
printInventions() that accepts the inventors, and inventions arrays; and,
the year array as returned by setInventionYear(). In the printInventions
method use a for loop to print the information from each array. The print for
the header has to be outside of the for loop because it's printed only once.

FAMOUS INVENTIONS

Inventor: Xxxxxxxxxxxx
Invention: Xxxxxxxxxxxx
Year Invented: ZZZ9

Inventor: Xxxxxxxxxxxx
Invention: Xxxxxxxxxxxx
Year Invented: ZZZ9

***END OUTPUT SPECS***

Grading Requirements: During lab class, enter your name on the sign-up
sheet for grading when your assignment is in gradable condition.

© Linda Shepherd: LE 2
© https://science.howstuffworks.com/innovation/famous-inventors: Search by inventor.
****SAMPLE OUTPUT****

How many inventors? 3

Enter inventor #1: Thomas Edison

Enter inventor #2: Alexander Graham Bell

Enter inventor #3: George Washington Carver

Enter Thomas Edison's invention: Tin Foil Phonograph

Enter Alexander Graham Bell's invention: Telephone

Enter George Washington Carver's invention: Pomade from Peanuts

Enter the year in which the tin foil phonograph was invented: 1877

Enter the year in which the telephone was invented: 1876

Enter the year in which the pomade from peanuts was invented: 1925

FAMOUS INVENTIONS

Inventor: Thomas Edison


Invention: Tin Foil Phonograph
Year Invented: 1877

Inventor: Alexander Graham Bell


Invention: Telephone
Year Invented: 1876

Inventor: George Washington Carver


Invention: Pomade from Peanuts
Year Invented: 1925

© Linda Shepherd: LE 3
© https://science.howstuffworks.com/innovation/famous-inventors: Search by inventor.

Вам также может понравиться