Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


quetypai
class
1 Answer(s)      a year and 10 months ago
Posted in : Java Beginners


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.


Advertisement
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();
    }
  } 
}


Related Tutorials/Questions & Answers:
class
class  Is a class a subclass of itself
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
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,, the super class of an exception is throwable class. and the super class of an throwable class is the object class
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
Explain final class, abstract class and super class.
Explain final class, abstract class and super class.  Explain final class, abstract class and super class.   Explain final class, abstract class and super class. A final class cannot be extended. A final class
.class and .tld
.class and .tld  how to create .class and .tld file
class loaders
class loaders   Explain static and dynamic class loaders
inner class
inner class  what is mean by inner class   Inner class is a non-static class which is defined inside another class
Node class
Node class   hii, What is a node class?   hello, A node class is a class that has added new services or functionality beyond the services inherited from its base 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
lock on a class
lock on a class  hello, Can a lock be acquired on a class?   hiii,, Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object
Java class
Java class  What is the purpose of the Runtime class
immutable class
immutable class  How to make a class immutable
Locale class
Locale class  What is the Locale class
singleton class
singleton class  What is singleton class
Abstract class
Abstract class  Can an abstract class be final
Abstract class
Abstract class  what is an Abstract class
printstrim class
printstrim class  discribe PrintStream class
printstrim class
printstrim class  discribe PrintStream class
wrapper class
wrapper class  list wrapper class methods
wrapper class
wrapper class  wrapper class methods
objective c extending a class with a class
objective c extending a class with a class  I need an example for extending a class with a class in objective c. thanks
objective c extending a class with a class
objective c extending a class with a class  I need an example for extending a class with a class in objective c. thanks
robot class
robot class  please send me uses of robot class and some examples using robot class
Nested class
Nested class  What is nested class?  when a class is defined within another class then such a class is called a nested class. Nested... readable and maintainable code. class OuterClass { ... static class
abstract class
abstract class  Can there be an abstract class with no abstract methods
java.sql.DriverManager class
java.sql.DriverManager class  Why isn't the java.sql.DriverManager class being found
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
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.
GregorianCalendar class
GregorianCalendar class   hello,, What is the GregorianCalendar class?   hii, The GregorianCalendar provides support for traditional Western calendars
Dictionary class
Dictionary class  hello,, What is the Dictionary class?   hii,, The Dictionary class provides the capability to store key-value pairs
abstract class
abstract class  abstract class AbstractClass{ } is possible and compile the class or any compile time error occur tell me the answer Blockquote
Sealed class
Sealed class  Hi........ What are sealed class? Please give an example Thanks  Ans: Sealed class: Sealed classes conserve memory..., and the compiler can provide better error feedback. The class which is not dynamic
Sealed class
between sealed class and dynamic classes? Please give me an example of each class Thanks  Ans: Dynamic class: Specifies that instances of a class may possess dynamic properties added at run time. Sealed class: Sealed
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
class and Object
class and Object  how many classes,References and objects in this following statement.... A a=new B();   Hi, In the statement: A a=new B(); There are 2 classes, Class A and Class B. References : 1 (Object of B
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
class distance
class distance  class distance-integer data member km1,km2,km3,m1,m2,m3. run()-to input the two distance and add them in the third. display()-to display the total distance. display the constructor if required
class name
class name  how to create a class named box thaT INCLUDES integer data fields for length,width,and height, include three contructors that require one,two,three arguments
wrapper class.
wrapper class.  Write short note on character wrapper class.   Java Character Wrapper class The Character class wraps a value of the primitive type char in an object. An object of type Character contains a single field
java class
send according of java class assoon as possible . Write a java program to display.... a. Create a window class. b. Create frame within the window class. c. Extend WindowAdapter class to display the message ‚??Window Closing‚
abstract class
abstract class  what is abstract class .why we use it or what is the need of this class?   Abstract class is like base class which contains abstract method and cannot instantiated.   Please go through
anonymous class
anonymous class  what actually is an anonymous class and what is the use of it along with the simple example? if there is a video explaining it that will be fine
Class and object
Class and object  what is exact meaning for the statement, A a1=new B();   Hi, Here is two classes A and B. A is super class and B is sub class. Here is the code example: public class A { public int i=40
class name
class name  what is the class name of circle.java   how do i complie my jdk file, what happen s if i put in the correct commands and it still does not complie, what do i do next
Abstract class
Abstract class  j   An Abstract class is a base class which cannot be instantiated but can be extended. It is always marked with an abstract keyword. For more information, visit the following links: http
Class and Instance
Class and Instance  class IdentifyMyParts { public static int x=7; public int y=3;} What are the class variable? What are the instance variables... = " +b.x);   Instance variables are declared in a class, but outside a method
 

 

 

DMCA.com