1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
galben [10]
3 years ago
13

Write an application that instantiates five Recording objects and prompts the user for values for the data fields. Then prompt t

he 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. Validations:

Computers and Technology
1 answer:
tangare [24]3 years ago
7 0

Answer:

Here is the JAVA application

Recording.java:

class Recording {  //class name

String title;  //String type variable to store the title of the song

String artist;  //String type variable to store the artist name of the song

int playingTime;  //int type variable to store the playing time of the song in seconds  

public String getTitle() {  //accessor method to get the title of the song

   return title; }   //returns the current title of song

public void setTitle(String title) {  //mutator method to set the title of song

   this.title = title;  }   // sets the title of song

public String getArtist() {  //accessor method to get the artist name of the song

  return artist; }   //returns the current artist name of song

public void setArtist(String artist) {  //mutator method to set the artist name of song

  this.artist = artist; }   //sets the artist name

public int getPlayingTime() {  //accessor method to get the playing time of the song

   return playingTime; } /  /returns the playing time of song

public void setPlayingTime(int pt) {  //mutator method to set the playing time of song

   this.playingTime = pt; }   //sets the playing time of song

public Recording(String title, String artist, int playingTime) {  //parmeterized constructor of Recording class that takes title, artist and playingTime as parameters

this.title = title;  

this.artist = artist;

this.playingTime = playingTime;  }  }

Explanation:

Here is the Main class:  

import java.util.Scanner;   //to accept input from user

public class Main {  

public static void main(String[] args) {  // start of main function

 Recording[] song = new Recording[5];  //creates object of Recording class named song to instantiate five Recording objects

 Scanner input = new Scanner(System.in);  //creates Scanner class object named input

 int i = 0;  // declare i and initialize it to -

 for (i = 0; i < song.length; i++) {  //iterates through the list of song

  int j = i + 1;  

  System.out.print("Enter the title of song " + j + ": ");  //prompts user to enter the title of song

 String title = input.nextLine();   //reads the title string from user

 System.out.print("Enter the artist of song " + j + ": ");  //prompts user to enter the artist of song

 String artist = input.nextLine();   //reads the artist string from user

System.out.print("Enter the playing time of song " + j + " in seconds: ");   //prompts user to enter the playing time of song

 String playtime = input.nextLine();  //reads the playing time string value from user

 int playingTime = Integer.parseInt(playtime);   // converts String value of playtime to integer

 song[i] = new Recording(title, artist, playingTime); }   //calls constructor of Recording class by passing title, artist and playingTime to it  

 int sort;  // for choosing which field to sort

do {  //continues to ask user to enter which field the Recordings should be sorted by

System.out.println("How should these songs be sorted? 1 for title 2 for artist 3 for playing time");  

sort = input.nextInt();  //reads user choice to sort

       if (sort > 0 && sort < 4) {  //to check if user enters a valid choice

 int a, b;  

 int max = song.length - 1;  

for (a = 0; a < max; a++) {  //iterates through the length of the song list setting an index variable a

      for (b = 0; b < max; b++) {    //iterates through the length of the song list setting an index variable b

  int c = b + 1;

     if (sort == 1) {  //if the user selects title field

       if (song[b].getTitle().compareTo(song[c].getTitle()) > 0) {  // compares title of one song with the song that comes after it

   Recording temp = song[b];  //sorts the titles using bubble sort by ordering each title to the immediate next and swapping them if they are not sorted already

   song[b] = song[c];

   song[c] = temp; } }  

   else if (sort == 2) {    //if the user selects artist field

  if (song[b].getArtist().compareTo(song[c].getArtist()) > 0) {  // compares artist of one song with the song artist  that comes after it

//sorts the artists using bubble sort by ordering each title to the immediate next and swapping them if they are not sorted already

     Recording temp = song[b];

     song[b] = song[c];

     song[c] = temp;  }  }  

   else if (sort == 3) {   //if the user selects playing time field

  if (song[b].getPlayingTime() > song[c].getPlayingTime()) {

/* compares artist of one song with the song artist  that comes after it sorts the artists using bubble sort by ordering each title to the immediate next and swapping them if they are not sorted already */

       Recording temp = song[b];

        song[b] = song[c];

         song[c] = temp;  } } } }  }  

             else {  //if user enters any invalid choice

 System.out.println("Invalid choice! Enter right choice"); }        

       } while (sort < 1 || sort > 3);  //keeps asking user to enter which field the recording to sort by until the value of sort in range of 1 to 3

for (i = 0; i < song.length; i++) {  //displays the sorted song list according to selected field

System.out.println("Song: Title: " + song[i].getTitle() + ". Artist: " + song[i].getArtist() + ". Playing time: " + song[i].getPlayingTime() + " seconds.");  }

input.close();  }  }

The output of the program is attached.

You might be interested in
Which CIDR network has the smallest possible number of hosts? a. 123.0.0.0/8 b. 123.45.0.0/16 c. 123.45.67.0/24 d. All have the
Lina20 [59]

Answer:

CIDR is based on a variable-length subnet masking technique, which allows a new method of representation for IP addresses. Routing prefix is written with a suffix number of bits of the name, such as 123.0.0.0/8, as the CIDR network has the smallest possible amount of hosts.

Explanation:

CIDR ( Class Inter-Domain Routing ) It is a method that is allocating IP addresses and routing the IP. CIDR is introduced in 1933 and replace the architecture of network design on the internet. CIDR slows down the growth of the routing across the web and helps to slow the IP addresses such as IPv4 addresses.

CIDR consists of two groups of bits in the address. In the new age, the network prefix identifies the whole network. This is used as the basis of routing between IP networks and allocation policies.

IPv4 in-network prefix is 8-bit groups.

A typical IPv4 address is 192.168.0.5 the lowest value is 0, and the highest value is 255

In the given choices, 123.0.0.0 / 8 of the possible smallest number of hosts.

8 0
3 years ago
Suppose we used an Internet Addressing protocol that used 4 bits to encode a single address. How many devices would be supported
Allushta [10]
C. is the answer my guy
8 0
2 years ago
The alumni development office at your university uses specialized software that can be accessed from two different servers. The
Agata [3.3K]

Answer:

Round-Robin DNS

Explanation:

According to my experience in Information Technology and Networking it can be said that based on the information provided the best solution would be to set up a Round-Robin DNS. This term refers to a technique used to balance the load on a server, where a client request is sent to each server one at a time, and then the system repeats the process from the top of the request list. This prevents the server from being drowned in a sea of simultaneous requests.

If you have any more questions feel free to ask away at Brainly.

6 0
3 years ago
To keep information beyond reach of unauthorized users, is to keep the information _____. Group of answer choices simple verifia
nasty-shy [4]

Answer:

Secure is the correct answer for the above question.

Explanation:

  • When any person wants that any information is not hacked by any user then he needs to secure the information with the help of any security mechanism. This security mechanism can be of any type that facilities the user to stop the information are being hacked.
  • The above question asked about the work which is needed to stop the message is being hacked. So there is a need to secure the information. so secure is the correct option while the other option is not valid because "simple, economical or verifiable" can not stop the message from accessed by the unauthorized user.
7 0
3 years ago
What is the process in which a server is partitioned into smaller components virtually
lilavasa [31]

The answer to your question is,

Server virtualization

-Mabel <3

3 0
2 years ago
Other questions:
  • A type of touch screen that can be up to four feet by six feet is a(n) _____. plasma screen multitouch interface Electronic Pape
    10·2 answers
  • Will upvote all answers
    7·1 answer
  • Prompt the user ‘Enter a row vector of any numbers’ in the command window, and enter an arbitrary row vector and store it to x.
    6·1 answer
  • andy accidentally saved a file in the wrong folder. what is the quickest way to move the file? create a new file and save it in
    8·2 answers
  • Can you clone apps form your PC and to other PC?<br>Yes or No
    13·2 answers
  • SATCOM in the Ku- and Ka- bands, as well as EHF systems are adversely affected by rain (the higher the frequency, the greater th
    14·1 answer
  • When a diaphragm contracts, a person is<br>Exhaling<br>Inhaling​
    12·2 answers
  • 1) SuperFetch is a memory-management technique that a) determines the type of RAM your system requires. b) makes the boot-up tim
    7·1 answer
  • The economic importance of computer viruses​
    14·2 answers
  • Identify the network and the host address in the ip address of 12.128.120.131 with a subnet mask of 255.128.0.0.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!