Question

In: Computer Science

in java Write an interface for a CD player. It should have the standard operations (i.e....

in java Write an interface for a CD player. It should have the standard operations (i.e. play, stop, nextTrack, previousTrack, etc.) that usual CD players have.

Solutions

Expert Solution

Interface in java

interface is defined as includes group of methods without body. it is a fully abstract class .In interface all the fields are public, static and final by default.Use interface keyword to create an interface and implements keyword is used for implement interface in class.

//create interface CDPlayer
interface CDPlayer{
//methods are public abstract by default and they have no body
void play(); //method for play
void stop(); //method for stop
void nextTrack(); //method for nextTrack
void previousTrack(); //method for previousTrack
}
//create class CDPlayers and implements interface
class CDPlayers implements CDPlayer{
  
//implement play abstract method
public void play()
{
System.out.println("Play Songs"); //print the message when methos is call
}
  
//implement stop abstract method
public void stop()
{
System.out.println("Stop songs"); //print the message when methos is call
}
  
//implement nextTrack abstract method
public void nextTrack()
{
System.out.println("Next song select for play"); //print the message when methos is call
}
  
//implement previousTrack abstract method
public void previousTrack()
{
System.out.println("Previous song select for play"); //print the message when methos is call
}
  
}
public class Main
{
   public static void main(String[] args) {
       CDPlayers cd = new CDPlayers(); //create object of CDPlayers class
       cd.play(); //call play method
       cd.stop(); //call stop method
       cd.nextTrack(); //call nextTrack method
       cd.previousTrack(); //call previousTrack method
   }
}

=======================================OUTPUT===============================

==Please Upvote==


Related Solutions

In Java Create an interface Create an interface Printing, which have a method getPageNumber () that...
In Java Create an interface Create an interface Printing, which have a method getPageNumber () that return page number of any printing. Create an abstract class named Novel that implements Printing. Include a String field for the novel's title and a double field for the novel price. Within the class, include a constructor that requires the novel title, and add two get methods--one that returns the title and one that returns the price. Include an abstract method named setPrice().. Create...
Suppose the interface and the class of stack already implemented, Write application program to ( java)...
Suppose the interface and the class of stack already implemented, Write application program to ( java) 1- insert 100 numbers to the stack                         2- Print the even numbers 3- Print the summation of the odd numbers
Using a (GUI interface), write a Java program that simulates an ATM machine with the following...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following options menu: "Welcome" 1. Deposit to account 2. Withdraw 3. Exit
write code in java and comment. thanks. the program is about interface . Implement the basics...
write code in java and comment. thanks. the program is about interface . Implement the basics of Fitness and types of Fitness: Aerobic. Implement specific Fitness types such as Swimming, Cycling, Fitness Task: public interface Fitness (10pts) This will be used as a starting point for deriving any specific Fitness type. Every fitness exercise type has one or more muscle group it affects. Therefor a Fitness has the following abstarct method (Note that all methods in an interface are abstract...
JAVA Add static methods largest and smallest to the Measurable interface. The methods should return the...
JAVA Add static methods largest and smallest to the Measurable interface. The methods should return the object with the largest or smallest measure from an array of Measurable objects.
Write a Java class called Person. The class should have the following fields: A field for...
Write a Java class called Person. The class should have the following fields: A field for the person’s name. A field for the person’s SSN. A field for the person’s taxable income. A (Boolean) field for the person’s marital status. The Person class should have a getter and setter for each field. The Person class should have a constructor that takes no parameters and sets the fields to the following values: The name field should be set to “unknown”. The...
Write a java program with the following classes: Class Player Method Explanation: play : will use...
Write a java program with the following classes: Class Player Method Explanation: play : will use a loop to generate a series of random numbers and add them to a total, which will be assigned to the variable score. decideRank: will set the instance variable rank to “Level 1”, “Level 2”, “Level 3”, “Level 4” based on the value of score, and return that string. getScore : will return score. toString: will return a string of name, score and rank....
in java, write code that defines a class named Cat The class should have breed, name...
in java, write code that defines a class named Cat The class should have breed, name and weight as attributes. include setters and getters for the methods for each attribute. include a toString method that prints out the object created from the class, and a welcome message. And use a constructor that takes in all the attributes to create an object.
Write an inventory program in java for a used car lot. You should have one Car...
Write an inventory program in java for a used car lot. You should have one Car parent class and child classes for 3 vehicle types (convertible, SUV, Classic, etc). The parent class should have 3 variables and 3 functions, each child class should have 1 variable unique to it and 1 function. Your program should allow the user to store up to 100 cars in the inventory and write the cars out to a file when done.
Write a java program using the information given Design a class named Pet, which should have...
Write a java program using the information given Design a class named Pet, which should have the following fields (i.e. instance variables):  name - The name field holds the name of a pet (a String type)  type - The type field holds the type of animal that a pet is (a String type). Example values are “Dog”, “Cat”, and “Bird”.  age - The age field holds the pet’s age (an int type) Include accessor methods (i.e. get...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT