Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WRITE THE PROGRAM IN JAVA. gram 3: Olympians I C 1 Goals To write your own class in a program To write a constructor with

WRITE THE PROGRAM IN JAVA.

image text in transcribedimage text in transcribedimage text in transcribed

gram 3: Olympians I C 1 Goals To write your own class in a program To write a constructor with parameters, an method and a toString) method. To use ArrayList To use a for-each loo . p *l . To use text file for output 2 The Context This is a single-class project, the first for which I have not given you code to start from. It is not realistic, or useful, but it gives us a place to start. This does not follow the MVC pattern for simplicity's sake. It is very important that you follow these instructions closely. They will guide you through learning a specific set of skills. Do not try to solve the problem some other way 2.1 The Olympian Class Create a class called "Olympian" to hold the facts about a member of the 2018 USA Olympic Team name, sport, numMedals and event 1. In this class, provide four private data members: name, sport, numMedals and event. 2. Create a constructor with four parameters (name, sport, numMedals and event) 3. Also provide a toString) method and a computeMedals) method The compute function. In your computeMedals), a static function, do all of the following 1. Take one parameter, an array of Olympian objects 2. Use a for-each loop to walk through the ArrayList 3. For each Olympian in the array: o get the numMedals using an accessor method (getter) o use the numMedals to add to the total number of medals for all the Olympians o return the total number of medals The main function. In your main function, do all of the following Output a welcome message to the console that includes the assignment name, P3: Olympians and your name 4. 5. Allocate an ArrayList of the class Olympian 6. In a loop, read in the name, sport, numMedals and event of each Olympian. Use these to create an Olympian object and add it to the Olympians ArrayList Validate input for NumMedals. It cannot be negative or more than 10 (Michael Phelps has 8) but it can be zero o 7. When input is finished, call the function named computeMedals), described above, and receive a return value that is the total medals received bv all the Olvmpians in vour list. Print this to the console with an appropriate label 8. Use a for-each loop to print the array of Olympians and show their name, sport, numMedals and event. Use proper labels and spacing so it looks like a table Open a file named "results.txt" for output and declare a Print Writer 9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

3 How the market system answers four fundamental questions.

Answered: 1 week ago