Concept explainers
a.
Explanation of Solution
Program:
File name: “Recording.java”
//Define a class named Recording
public class Recording
{
//Declare the variables
private String song;
private String artist;
private int playTime;
//Define a set method that takes the Recording’s title
public void setSong(String title)
{
//Assign the value
song = title;
}
//Define a set method that takes the Recording’s artist
public void setArtist(String name)
{
//Assign the value
artist = name;
}
/*Define a set method that takes the Recording’s playing time*/
public void setPlayTime(int time)
�...
b.
Explanation of Solution
Program:
File name: “RecordingSort.java”
//Import necessary header files
import javax.swing.*;
//Define a class named RecordingSort
public class RecordingSort
{
//Define a main method
public static void main(String[] args)
{
//Declare an array of five Recording objects
Recording[] recordings = new Recording[5];
//Declare the variables
int x;
String song, artist, timeString, order, message = "";
int time;
//For loop to be executed until x exceeds 5
for(x = 0; x < recordings.length; ++x)
{
//Prompt the user to enter a song for recording
song = JOptionPane.showInputDialog(null,
"Enter a song for recording " + (x + 1));
//Prompt the user to enter an artist for recording
artist = JOptionPane.showInputDialog(null,
"Enter an artist for recording " + (x + 1));
//Prompt the user to enter the time for the recording
timeString = JOptionPane.showInputDialog(null,
"Enter the time for the recording in seconds" + (x + 1));
time = Integer.parseInt(timeString);
//Declare a temp object
Recording temp = new Recording();
//Function Call
temp.setArtist(artist);
temp.setSong(song);
temp.setPlayTime(time);
//Assign the value
recordings[x] = temp;
}
/*Prompt the user to enter the choice of displaying
the objects in order by song title, artist, or playing time*/
order = JOptionPane.showInputDialog(null,
"By which field do you want to sort?\n" +
"(S)ong, (A)rtist, or (T)ime");
//If the user enters a choice, song title
if(order.charAt(0) == 'S')
//Function call
sortBySong(recordings);
//If the user enters a choice, Artist
else
if(order.charAt(0) == 'A')
//Function call
sortByArtist(recordings);
//Else the user enters a choice, playing time
else
//Function call
sortByTime(recordings);
//For loop to be executed until x exceeds 5
for(x = 0; x < recordings.length; ++x)
//Print the message
message = message + "\nartist: " + recordings[x].getArtist() +
" song: " + recordings[x].getSong() + " time: " +
recordings[x].getPlayTime();
JOptionPane.showMessageDialog(null, message);
}
/*Define a method to sort the Recording objects in
artist order*/
public static void sortByArtist(Recording[] array)
{
//Declare the variables
int a,b;
Recording temp;
String stringB, stringBPlus;
int highSubscript = array.length - 1;
//For loop to be executed until a exceeds highSubscript
for(a = 0; a < highSubscript; ++a)
//For loop to be executed until b exceeds highSubscript
for(b = 0; b < highSubscript; ++b)
{
stringB = array[b]...
Trending nowThis is a popular solution!
- Radio station KJAVA wants a class to keep track of recordings it plays. Create a class named Recording that contains fields to hold methods for setting and getting a Recording’s title, artist, and playing time in seconds. Write an application that instantiates five Recording objects and prompts the user for values for the data fields. Then prompt the user to enter which field the Recordings should be sorted by—(S)ong title, (A)rtist, or playing (T)ime. Perform the requested sort procedure, and display the Recording objects. Given classes: public class Recording { privateString song; privateString artist; privateint playTime; publicvoidsetSong(Stringtitle) { } publicvoidsetArtist(Stringname) { } publicvoidsetPlayTime(inttime) { } publicStringgetSong() { } publicStringgetArtist() { } publicintgetPlayTime() { } } import java.util.*; public class RecordingSort { publicstaticvoidmain(String[] args) { // Write your code here } publicstaticvoidsortByArtist(Recording[] array) { //…arrow_forwardCreate the StockTask1 Java project Create a Stock object class that contains the following information: The symbol of the stock is stored in a private string data field called symbol. The stock's name is stored in a private string data field called name. previousClosingPrice is a private double data area that stores the stock price for the previous day. currentPrice is a private double data area that stores the stock price at the current time. A constructor for creating a stock with the given symbol and name. For the data fields, there are accessor methods (get-methods). For the data fields, there is a mutator method (set-methods). A method named getChangePercent()that returns the percentage changed from previousClosingPrice to currentPrice. Formula:perc_change = (current price - previous closing price) / previous closing price x 100 Create a test class named testStockthat creates a Stockobject with the stock symbol SUNW, the name Sun Microsystems Inc., and the previous closing…arrow_forwardDesign a class named CustomerRecord that holds a customer number, name, and address. Include separate methods to 'set' the value for each data field using the parameter being passed. Include separate methods to 'get' the value for each data field, i.e. "return" the field's value. Pseudocode:arrow_forward
- Creating Enumerations In this section, you create two enumerations that hold colors and car model types. You will use them as field types in a Car class and write a demonstration program that shows how the enumerations are used. 1. Open a new file in your text editor, and type the following Color enumeration: enum Color {BLACK, BLUE, GREEN, RED, WHITE, YELLOW}; 2. Save the file as Color.java. 3. Open a new file in your text editor, and create the following Model enumeration: enum Model {SEDAN, CONVERTIBLE, MINIVAN}; 4. Save the file as Model.java. Next, open a new file in your text editor, and start to define a Car class that holds three fields: a year, a model, and a color. public class Car { private int year; private Model model; private Color color; 5. Add a constructor for the Car class that accepts parameters that hold the values for year, model, and color as follows: public Car(int yr, Model m, Color c) { year = yr; model = m; color = c; } 6. Add a display()…arrow_forwardIntroduction In this project, you will complete a C++ class by writing a copy constructor, destructor, and assignment operator. Furthermore, you will write a tester class and a test program and use Valgrind to check that your program is free of memory leaks. Finally, you will submit your project files on GL. If you have submitted programs on GL using shared directories (instead of the submit command), then the submission steps should be familiar. In this project we develop an application which holds the information about a digital art piece. There are two classes in this project. • The Random class generates data. The implementation of this class is provided. It generates random int numbers for colors. To create an object of this class we need to specify min and max values for the constructor. The colors fall between 30 and 37 inclusively. The Art class generates random colors and stores the color values. You implement the Art class. An object of the Art class is a digital masterpiece.…arrow_forwardComputer Science Help with C# programming in Microsoft Visual Studio: You will be creating a program that uses a GUI to allow the user to enter information about an employee. In addition to the main class you create, there will also be four additional classes named fileOutput, baseEmployee, superEmployee and advancedEmployee which you will have to create. For this problem, the baseEmployee class will need to accept user input for a name, email and address for a base employee. The advancedEmployee class should be able to extend the baseEmployee, by allowing an hourly rate and hours worked to be entered. Hours worked must be in the range of 0 to 80 and hourly rate is in the range of 10 to 42.50. The superEmployee class will then extend the advancedEmployee class and allow permission level of high, medium or low to be entered, along with their office number. The program should show a radio button that allows the user to choose whether or not the user is a base employee, advanced…arrow_forward
- Mick’s Wicks makes candles in various sizes. Create a class for the business named Candle that contains the following data fields: color - of type String height - of type int price - of type double Create get methods for all three fields. Create set methods for color and height, but not for price. Instead, when height is set, determine the price as $2 per inch. Create a child class named ScentedCandle that contains an additional data field named scent (of type String) and methods to get and set it. In the child class, override the parent’s setHeight() method to set the price of a ScentedCandle object at $3 per inch.arrow_forwardPYTHON Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. Once you have written the class, write a program that creates three Employee objects to hold the following data, then save the data in (employee.txt) filearrow_forwardin addition to java programming please include the flowchart of the program for the project and the pseudocode of the program for the project. Create a program to enter grades and calculate averages and letter grades. Need a class which will contain: Student Name Student Id Student Grades (an array of 3 grades) A constructor that clears the student data (use -1 for unset grades) Get functions for items a, b, and c, average, and letter grade Set functions for items a, n, and c Note that the get and set functions for Student grades need an argument for the grade index. Need another class which will contain: An Array of Students (1 above) A count of number of students in use You need to create a menu interface that allows you to: Add new students Enter test grades Display all the students with their names, ids, test grades, average, and letter grade Exit the program Add comments and use proper indentation. Nice Features: I would like that system to accept a student with no…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT