
can any body give me idea how to write code for
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.

Here are the codes of classes country.java and MedalTally.java.
Country.java
class Country{
static String countryName;
static String gold;
static String silver;
static String bronze;
static String totalMedals;
public Country(String countryName, String gold, String silver, String bronze, String totalMedals)
{
this.countryName=countryName;
this.gold=gold;
this.silver=silver;
this. bronze = bronze;
this. totalMedals = totalMedals;
}
public static String getName()
{
return countryName;
}
public static String getGold()
{
return gold;
}
public static String getSilver()
{
return silver;
}
public static String getBronze()
{
return bronze;
}
public static String getTotalMedals()
{
return totalMedals;
}
}
MedalTally.java
import java.io.*;
import java.util.*;
public class MedalTally
{
ArrayList<Country> list;
public MedalTally()
{
list = new ArrayList<Country>();
}
public void addEntry(Country x)
{
list.add(x);
}
public void write() throws java.io.IOException
{
FileWriter fw = new FileWriter("olympics.txt", true);
PrintWriter write = new PrintWriter(fw);
for(int index =0; index < list.size(); index++)
{
Country x = list.get(index);
write.println(x.getName()+" "+x.getGold()+" "+x.getSilver()+" "+x.getBronze()+" "+x.getTotalMedals());
write.close();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.