Question: This is my assignment: Write a program that will compile a list of instruments from different instrument families. A family of musical Instruments is a

This is my assignment:

Write a program that will compile a list of instruments from different instrument families. A family of musical Instruments is a grouping of several different but related sizes or types of instruments.

Some commonly recognized families are:

Brass Family - A brass instrument is a musical instrument that produces sound by sympathetic vibration of air in a tubular resonator in sympathy with the vibration of the player's lips. Ref: https://en.wikipedia.org/wiki/Brass_instrument (Links to an external site.)Links to an external site.

Strings Family - String instruments, stringed instruments, or chordophones are musical instruments that produce sound from vibrating strings. Ref: https://en.wikipedia.org/wiki/String_instrument (Links to an external site.)Links to an external site.

Woodwind Family - Woodwind instruments are a family of musical instruments within the more general category of wind instruments. There are two main types of woodwind instruments: flutes and reed instruments (otherwise called reed pipes). What differentiates these instruments from other wind instruments is the way in which they produce their sound. Ref: https://en.wikipedia.org/wiki/Woodwind_instrument (Links to an external site.)Links to an external site.

Percussion Family - A percussion instrument is a musical instrument that is sounded by being struck or scraped by a beater (including attached or enclosed beaters or rattles); struck, scraped or rubbed by hand; or struck against another similar instrument. Ref: https://en.wikipedia.org/wiki/Percussion_instrument (Links to an external site.)Links to an external site.

Constraints

Limit the number of families to the list above

Use one separate (external to the main class) abstract superclass: Instrument

Use three separate (external to the main class) abstract subclasses that extend Instrument:

o BlownInstrument o Fingered o Struck

Use four separate (external to the main class) subclasses (families) that extend the appropriate three above:

o Brass o Strings o Woodwind o Percussion

Requirements

Display the menu shown in the downloadable PDF example

Request the number of instruments to be entered

All instruments should be placed into an array (you can use one array per family or one array for all entered) so they may be displayed

Use set and get methods where appropriate

Implement a loop that will allow the user to enter more instruments

Use exception handling and validation where appropriate

This assignment will use coding principles learned from week 1 through 13

Hints

Make sure you use Java coding conventions

This is what I have done so far:

package AbstractClasses;

//Imports import java.util.ArrayList; import java.util.Scanner;

//Begin Class AbstractClasses public class AbstractClasses {

//Begin Main Method @SuppressWarnings("empty-statement") public static void main(String[] args) {

int instrumentFam;

Scanner input = new Scanner(System.in);

System.out.println("Select one of the following instrument families: "); System.out.println("1.Brass 2.String 3.Woodwind 4.Percussion " + "5.Display all instruments 6.Exit"); System.out.println("->: "); instrumentFam = input.nextInt();

int amount; String nameOfinstrument = null; String choice;

if (instrumentFam == 1) { ArrayList BrassFam; BrassFam = new ArrayList<>();

System.out.println("How many brass instruments would you like to enter? "); amount = input.nextInt(); for (int i = 1; i <= amount; i++) { System.out.println("Enter instrument #" + i + "->:"); nameOfinstrument = input.next(); } System.out.println("Display Instruments? Y for Yes, N for no"); choice = input.next(); { if (choice.equalsIgnoreCase("Y")); { BrassFam.add(nameOfinstrument); System.out.println(); } } if(choice.equalsIgnoreCase("N")); { System.out.println("Enter more instruments? "); } } } }

__________________________________________________________

package abstractclasses;

//Imports import java.util.ArrayList; import java.util.List;

//Begin Subclass Instrument public class Instrument extends AbstractClasses {

ArrayList BrassFam = new ArrayList<>();

public List getBrassFam() { return BrassFam; }

public void addBrassFam(String BrassFam){ this.BrassFam.add(BrassFam); } } //End Subclass Instrument

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!