wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Program to create medal tally and update it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Program to create medal tally and update it" Watch "Program to create medal tally and update it" New topic
Author

Program to create medal tally and update it

Prakash Chetry
Greenhorn

Joined: Sep 24, 2012
Posts: 5
Hi,

I need to write a program to create a medal tally of olympics and update it. Is there anyone available with whom I can discuss and progress??

Thanks,
Prakash
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

Welcome to the Ranch. This is not a live chatbox, but why don't you just explain exactly how far you've come, where you are stuck and what you need to know to get on with the problem.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Prakash Chetry
Greenhorn

Joined: Sep 24, 2012
Posts: 5
I am just goint to start doing it.

This is the detail

Country.java is a class to represent a country in medal tally. It has an attribute of
country name, and attributes to record the numbers of gold, silver, bronze, and total
medals. In this class, you should also define constructors, and assessor, mutator
methods.
Task 2
MedalTally.java is a class to model a medal tally, containing all the countries winning
any medal in an Olympic Games. It uses an array, Country[], to store medal records of
countries. Define constructors and relevant methods to manage the medal tally.
Task 3
The driver program, LondonGames.java starts by calling the load( ) method. This
method prompts (asks) the user for the name of an input text file. The load( ) method
must check that the requested file exists and is not empty. This is to be done using the
Java File class, not try/catch blocks.
If the text file exists and is not empty, then the contents of the text file are read into the
Country[] array.
The format of each record of this file is country name, numbers of gold, silver, bronze and
total medals separated by white space. For example, the first line of the provided input file,
London2012.txt, which stores the top 20 countries on the medal tally at August 11,
2012:
United States of America 41 26 27 94
means USA had 41 gold medals, 26 silver, 27 bronze, and total 94 medals.
After the file has been read into the array, the file is closed. All further uses of this program
are with the array, not the file, except, of course, for saving the array back to a file. After
the file has been read, the user is presented with the main menu, as follows:
Welcome to the London Olympic Games Medal Tally
Main Menu
1. Add Country
2. Delete Country
3. Add Medal(s)
4. Display Medal Tally
5. Save to file
6. Exit
Enter choice >>
Implement the functionality of each method as follows (assume user input is correct):
1. Add Country
Add Menu
1. Country Name
2. Exit
Enter choice >>
The Add menu presents the user with a sub-menu as shown above
Picking choice 1 will attempt to add a new Country to the medal tally. This means
that a new Country object will created and inserted to the Country[] array that
represents the medal tally. The user will be asked to input the name of a new
country. At this stage the new country has no medals; you can add medal(s) from the
main menu after the country is added.
Selecting choice 2 returns the program to the main menu
2. Delete Country
Selecting this main menu choice prompts (asks) the user for the country name at
which to attempt to remove from the medal tally. Only one Country can be removed
per call to this menu choice. After deletion, the program returns to the main menu.
3. Add Medal(s)
This menu choice prompts (asks) the country name, and numbers of gold, silver and
bronze medals to add to that country, which is already on the tally.
4. Display Medal Tally
This choice displays all the countries and numbers of medals. After display, the
programs returns to the main menu.
5. Save to file
When this option is selected, the user is asked for the name of a text file. If the file
can be opened, then the contents of the entire array is written into the file.
The format of the output must be the same as the format of the input file. The output
file must be able to be used as input file the next time the program is run.
The program does NOT exit when this menu choice is chosen. After writing to the
output file, the program returns to the main menu
6. Exit
Selecting this option exits the program. The user is NOT asked if they want to save
changes.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Jesper de Jong wrote:explain exactly ... where you are stuck and what you need to know to get on with the problem.
Prakash Chetry
Greenhorn

Joined: Sep 24, 2012
Posts: 5
I am just not getting how to start.....I am not a programmer I just know some basics......so I wanted to learn how to start.

Thanks
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

If you're brand new to programming in Java, then have a look at the Oracle Java Tutorials.

You'll first have to learn the basics before you start with an assignment like the one you posted above. In Oracle's tutorial you can learn how to write your first Java program, and learn the basics of the Java programming language. Make sure you understand the basics first.

Do you know what classes, objects, methods, variables etc. are? Then the first part of the assignment should not be very difficult:
Country.java is a class to represent a country in medal tally. It has an attribute of
country name, and attributes to record the numbers of gold, silver, bronze, and total
medals. In this class, you should also define constructors, and assessor, mutator
methods.

Try creating a class Country with the specified attributes. Post it here if you're unsure if you did it correctly, and ask questions if you don't know how to do something.
Prakash Chetry
Greenhorn

Joined: Sep 24, 2012
Posts: 5
Hi Jasper,

I have the basic knowledge and I think practicing is better than reading. Thanks for your reply.

I have designed the first two classes.




[/code]
Prakash Chetry
Greenhorn

Joined: Sep 24, 2012
Posts: 5
The first two classes work really good.

In the third class i.e. londongames I have to do different tasks using control structures. I am just getting confused in that. When I add a country it is not getting added to the London2012.txt and I am also confused about how to delete a country and display all the result. I have added some coding as comments but not sure whether they are correct or not.

Thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

again:
Jesper de Jong wrote:explain exactly ... where you are stuck and what you need to know to get on with the problem.

When you code, you should focus on ONE thing at a time. Don't worry about deleting a country or displaying all the results until you can get the adding a country to work.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Prakash Chetry wrote:I think practicing is better than reading.


Both are absolutely required. If you're not willing to do a fair amount of reading, your "practicing" will actually amount to just floundering around in the dark.

And here's a good article for when you're stuck and dont' know where to start: http://home.earthlink.net/~patricia_shanahan/beginner.html

Finally, I can't emphasize strongly enough how much I agree with Fred's advice to do things in small pieces.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program to create medal tally and update it