Write the output from your instrument class methods

Assignment Help Programming Languages
Reference no: EM13787200

This project focuses on demonstrating your understanding of classes and objects. Before attempting this project, be sure you have completed all of the reading assignments listed in the syllabus to date, participated in the weekly conferences, and thoroughly understand the examples throughout the chapters. The project requirements include:

Design and implement a stringed musical instrument violin class using the following guidelines:

Data fields for violin should include number of strings, an array of string names representing string names (e.g. E,A,D,G), and boolean fields to determine if the instrument is tuned, and if the instrument is currently playing. You are welcome to add additional data fields if you like.

A constructor method that set the tuned and currently playing fields to false.

Other methods

1) to tune the instrument

2) to start the instrument playing

3) to stop the instrument from playing.

4) return number of strings

5) return an array of string names representing string names (e.g. E,A,D,G)

Create a UML class diagram using a diagram tool (e.g. PPT, Visio) of your choice. Prepare the diagrams and place them in a word document along with a brief description of each of your classes.

Create Java classes for your instruments. Be sure that your code matches your design specifications and some minimal functionality is included. For example, if you called the violin.play() method, you should at least print that the violin is playing. Similar functionality should be supplied when you stop playing, tune or call any of your methods. For example:

public void playviolin() {

System.out.println("The violin is now playing.");

}

Write the output from your Instrument class methods to a text file that a user entered from the command line arguments (e.g. java violinOutput.txt). This allows your program to accept filenames from the user via a command line argument.

Finally, create a Java test class that simulates using your instrument class. In your test class be you should at a minimum: a) Construct 10 instances of your instrument, b) tune your instruments, c) Start playing your instrument, d) Call your unique method such as write string numbers and names, and e) Stop playing your instruments. (Hint: Arrays and Loops will make your job easier and result in more efficient code!)

Your programs should compile and run without errors.

Be sure

import java.io.*;

public class Test{

public static void main(String[] args) {

String outputFile = "";

if (0 < args.length) {

outputFile = args[0];

System.out.println("This program will write output to this file: " + outputFile + "\n");

try {

File file = new File(outputFile);

PrintWriter output = new PrintWriter(outputFile);

output.println("hello"); //to check if ir prints anything

Violin[] simpleViolin = new Violin[5];

//Create 5 violin objects

for (int i = 0; i < simpleViolin.length; i++){

simpleViolin = new Violin();

}

output.println("\nLet's tune " + Violin.getNumberOfViolins() + " violins.");

for(int i = 0; i < simpleViolin.length; i++){

output.print(i + 1);

simpleViolin.tuneOn();

}

output.println("\nNow let's start playing " + Violin.getNumberOfViolins() + " violins.");

for(int i = 0; i < simpleViolin.length; i++){

output.print(i + 1);

simpleViolin.startPlaying();

}

output.println("\nIt looks like " + Violin.getNumberOfViolins() + " violins have untuned.");

for(int i = 0; i < simpleViolin.length; i++){

output.print(i + 1);

simpleViolin.tuneOff();

}

output.println("\nThis music is terrible! Let's stop it!");

for(int i = 0; i < simpleViolin.length; i++){

output.print(i + 1);

simpleViolin.stopPlaying();

}

output.close();

}

catch (IOException io){

System.out.println("Sorry that file is not found " + io);

}

}//end if

}//end main

}//end Test

class Violin{

private final int numberOfStrings = 4;

private final char[] stringNames = {'E', 'A', 'D', 'G'};

private boolean isTuned = false;

private boolean isPlaying = false;

private static int numberOfViolins = 0;

private PrintWriter output;

public Violin(){

numberOfViolins++;

}

public void startPlaying() {

isPlaying = true;

System.out.println(" violin is now playing.");

}

public void stopPlaying() {

isPlaying = false;

System.out.println(" violin has stopped playing.");

}

public void tuneOn() {

isTuned = true;

System.out.println(" violin is now tuned.");

}

public void tuneOff() {

isTuned = false;

System.out.println(" violin is untuned.");

}

static int getNumberOfViolins(){

return numberOfViolins;

}

}

Reference no: EM13787200

Questions Cloud

Objectives and goals of the bill : Prepare a 750- to 1,050-word proposal addressing the following: Objectives of the bill, Goals of the bill and Possible solutions for the bill
Determine effective techniques for improving communications : Determine effective techniques for improving communications during negotiation.
Create copy for a poster or welcome flyer : Your task now is to create copy for a Poster or Welcome Flyer in which you invite new employees to your training session. (Just the words - phrases, short sentences, but no art work is required at this time!)
Explain what the consequences of the destruction of car are : Allis enters into a contract to buy a restored Model T car. At the time the contract is entered into, the Model T has not yet been restored. Prior to completion of the restoration, a fire destroys the car. Explain what the consequences of the dest..
Write the output from your instrument class methods : Write the output from your Instrument class methods to a text file that a user entered from the command line arguments (e.g. java violinOutput.txt). This allows your program to accept filenames from the user via a command line argument.
What types of goals are suitable for diversity training : What types of goals are suitable for diversity training.
Theories of morality values and consequences : In your discussion, be sure to address the following: theories of morality, values, and consequences and judicial ethics and responsibility and implications of judicial misconduct
Part of the accounting process : Bookkeeping differs from accounting in that bookkeeping primarily involves which part of the accounting process?
Write a script that calculates the squares and cubes : Write a script that calculates the squares and cubes of the numbers from 1 to 6 and outputs HTML5 text that displays the resulting values in an HTML5 table format, as shown below.

Reviews

Write a Review

Programming Languages Questions & Answers

  Build a student record managing system application

Build a student record managing system application

  Draw application to display button and label on a screen

Draw and implement application which displays a button and a label on a screen. Every time button is pushed, the label will display random number between 1 and 1000,

  Creating class savingsaccount using static variable

Create class SavingsAccount. Use static variable annualInterestRate to store annual interest rate for all account holders.

  Data members to store values of the two loans

A class that represents a person who belongs to a SACCO has two data members to store values of the two loans the person owes the SACCO. Add a parameterized constructor that initializes these loans using the two values passed as arguments.

  Create new method for random turning

Create new method named randomTurn (this method has no parameters and returns nothing). Select the code that does the random turning.

  Draw a gui to create objects

Draw a GUI that will create the objects and provide access to each object's processing methods. Use the drawing tool in Microsoft Word.

  Write simple program to prompt user for gross salary

Write simple program which will prompt user for his or her gross salary. Your program than will display net salary whereby 11.00% of the gross salary is deducted for EPF

  Create project to compute checking account balance

Create a project to compute your checking account balance. Form: Include radio buttons to indicate the type of transaction: deposit, check, or service charge.

  Write down program to arbitarily choose numbers

Write down a program to arbitarily select the numbers of 3 finalist to recieve a prize. Ensure not to choose same number twice. For instance picking finalist 3, 15, 29 woul valid but picking 3,3,31 would be invalid.

  Program to accept candy name price per pound

A program that accepts a candy name (for example, "chocolate-covered blueberries"), price per pound, and number of pounds sold in the average month, and displays the item's data.

  Write program which prompts user for interger value

Write a program which prompts user for interger value in range 0 to 32,767 and then prints infividual digits of numbers on line with three spaces between digits.

  Display the contents of the astack in reverse order

Write a pseudocode/function that will delete from an unsorted linked list of integers the node that contains the smaller integer. Can you do this with a single traversal of the list?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd