class
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.
View Answers
October 11, 2012 at 4:35 PM
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();
}
}
}
Ads
Related Tutorials/Questions & Answers:
class
is a
class to represent a country in medal tally. It has an attribute of
country...
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
Class
Class, Object and Methods
Class : Whatever we can see in this world all
the things... is termed as
a
class. All the
objects are direct interacted with its
class
Advertisements
Class
Class
This section explores the concept of
a
class in reference to object oriented programming techniques. A
class defines
the properties of objects and methods used
class loaders
class loaders
Explain static and dynamic
class loaders
class file
class file How to create
class file in jsf easily
inner class
inner class what is mean by inner
class
Inner
class is a non-static
class which is defined inside another
class
Matrix Class
Matrix
Class A
class to manage matrices and add them. Create in the driver
class two objects of it and use the add method
Matrix Class
Matrix
Class A
class to manage matrices and add them. Create in the driver
class two objects of it and use the add method
Adapter Class
Adapter Class Hello Everybody, Can anybody help me to describe what is Adapter
class and when to use this
class and give a suitable example... visit the following links:
What is Adapter
Class
Example of Adapter
Class
class file
class file how to convert java classfile into java sourcefile
create a class
create a class plz provide any example related to
class
super class
super class which is the super base
class in java
wrapper class
wrapper class why wrapper
class does not have a default constructor
Wrapper Class
Wrapper Class what is wrapper
class in java and why we use it
Hi Friend,
Wrapper
class is a wrapper around a primitive data type. It represents primitive data types in their corresponding
class instances e.g.
abstract class
abstract class abstract
class AbstractClass{
}
is possible and compile the
class or any compile time error occur tell me the answer
Blockquote
abstract class
abstract
class Explain the concept of abstract
class and it?s use with a sample program.
Java Abstract
Class
An abstract
class is a
class that is declared by using the abstract keyword. It may or may not have
Inner class
Inner class how can i call outer
class A `s method to print Outer.
class A { void m() { System.out.println("outer"); } }
public
class TestInners {
public static void main(String[] args) {
new
Class Loader
Class Loader What is
class loader? Explain in detail.
The Java ClassLoader is a an abstract
class which extends the Object
class. Java
class loader is a part of the Java Runtime Environment that dynamically loads
Class Loader
Class Loader What is
class loader? Explain in detail.
The Java ClassLoader is a an abstract
class which extends the Object
class. Java
class loader is a part of the Java Runtime Environment that dynamically loads
java class
java class write a java program to display a msg "window closing" when the user attempts to close the window.(a) create a window
class (b) create frame within the window
class (c) extends window adapter
class to display the msg