Question

Implement the following class in Java. Class name: Cakes Constructor Summary: public Leaderboard() - Create a...

Implement the following class in Java.

Class name: Cakes

Constructor Summary:

public Leaderboard() - Create a leaderboard with no entries, and current number of cakes eaten to 0.

Methods:

public List getContestants() - Return a list of all the contestant scores in the format (Name:Score). Return an empty list if no entries inside list.

Please provide a test to show your implementation works, thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

code:

import java.util.ArrayList;
import java.util.List;

public class LeaderBoard {
   List<String> name= new ArrayList<String>();
   int numberOfCakesEaten;
  
   public LeaderBoard()
   {
       this.name= null;
       this.numberOfCakesEaten= 0;
   }
   public List getContestants() //This is the getContastants method
   {
       return this.name;
   }
   public static void main(String[] args) { //Driver method
       LeaderBoard lead= new LeaderBoard();
       System.out.println(lead.getContestants());
      
   }

}
Output:

Hit the thumbs up if you liked the answer. :)

Add a comment
Know the answer?
Add Answer to:
Implement the following class in Java. Class name: Cakes Constructor Summary: public Leaderboard() - Create a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement the following class in Java: Class name: People Constructor Summary: public People (Str...

    Implement the following class in Java: Class name: People Constructor Summary: public People (String name) Methods: public People(String name) public void setName(String name) public String getName() Class name: Truck Constructor Summary: public Truck (int licensePlate, int onBoard, People people) Initially, the truck does not contain any on board the vehicle. If the number of people on board the vehicle is a negative number, the value of onBoard should be stored as zero. Methods: public int getLicensePlate() Returns license plate of...

  • JAVA Create a Java project to implement a simple Name class. This class will have the...

    JAVA Create a Java project to implement a simple Name class. This class will have the following class variable: First Name, Middle Name, Last Name, and Full Name Create the accessor/getter and mutator/setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Create a main() method to test your project.

  • Create a public constructor (a method with the same name as the class) inside the class...

    Create a public constructor (a method with the same name as the class) inside the class Fish. This constructor should take in no arguments. Inside the constructor, set typeOfFish to “Unknown” and friendliness to 3, which we are assuming is the generic friendliness of fish.

  • Create a java class that implements BagInterface using singly linked data. Name this new class LinkedBag....

    Create a java class that implements BagInterface using singly linked data. Name this new class LinkedBag. Be sure to include a default constructor to initialize the private members of the class. Test that your code works properly. BagInterface includes the methods:  public int getCurrentSize(); public boolean isEmpty(); public boolean add(T newEntry); public T remove(); public boolean remove(T anEntry); public void clear(); public int getFrequencyOf(T anEntry); public boolean contains(T anEntry); public T[] toArray();

  • Implement the following classes in the UML: 1. List class includes:       constructor List(): Create an...

    Implement the following classes in the UML: 1. List class includes:       constructor List(): Create an empty list with a length of 100. Hint: double [] list = new double [100];       constructor List(len: int): Create a List with a user specified maximum length. Hint: double [] list = new double [len];       add: add a new element to the end of the unsorted list.       print: display the list 2.SortedList class includes       two constructors : similar to the...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

  • In Java. What would the methods of this class look like? StackADT.java public interface StackADT<T> {...

    In Java. What would the methods of this class look like? StackADT.java public interface StackADT<T> { /** Adds one element to the top of this stack. * @param element element to be pushed onto stack */ public void push (T element);    /** Removes and returns the top element from this stack. * @return T element removed from the top of the stack */ public T pop(); /** Returns without removing the top element of this stack. * @return T...

  • Create a class called planet with private members name, percent02, temp. Create a constructor prototype and...

    Create a class called planet with private members name, percent02, temp. Create a constructor prototype and implementation. In the main, create 2 objects of class planet, one with arguments and the other without. Create a function to change name, percent02 and temp after the object has been created and a function that displays the current values of the members. Implement the operations specified above in the main of your program. This is all in C++, please help.

  • Create a C++ project with 2 classes, Person and Birthdate. The description for each class is...

    Create a C++ project with 2 classes, Person and Birthdate. The description for each class is shown below: Birthdate class: private members: year, month and day public members: copy constructor, 3 arguments constructor, destructor, setters, getters and age (this function should return the age) Person class: private members: firstName, lastName, dateOfBirth, SSN public members: 4 arguments constructor (firstName, lastName, datOfBirth and SNN), destructor and printout Implementation: - use the separated files approach - implement all the methods for the 2...

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT