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

  Assembly language instructions into machine code

The assembly instructions are stored in a file. Each line of the file stores exactly oneinstruction. The name of the file should be provided to the program as a command line argument.

  Write statement to determine whether array elements are full

Write the statements needed to determine whether any of the the array elements are null or refer to the empty String. Set the variable hasEmpty to true if any elements are null or empty-- otherwise set it to false.

  What is the throughput of the system

what is the throughput of the system

  What criterion is being used to determine best estimates

What we would like to do is create similar tables in an .rtf file that produces the same statistics for any numerical value against each level of a know classification/factor from any data set we wish to inspect.

  Develop a program to input miles driven and gallons for tank

Develop a program in C++ that will input the miles driven and gallons used (both as integers) for each tankful. The program should calculate and display the miles per gallon obtained for each tankful.

  Design a modularized body mass index program

Design a modularized Body Mass Index (BMI) Program which will calculate the BMI of a team player. The formula to calculate the BMI is as follows:

  Design a pseudo code to create the program

Design a pseudo code to create, debug and execute the program. The documentation should include your name, course, program name, due date, programming language used

  Find out the total of balances

Display all the contents of the file in a tabular format with the first row being a header row and write to a file that is called account numbers.txt only the account numbers from the read file.

  Read each line and create one complex object

Write all complex objects to file complexObj.txt and compute sum of all objects and append the object to the end of complexObj.txt

  Write program that asks user for initial

Write a program that asks a user for his/her first initial. Then ask the user to type 1,2 3, 4. When the user types 4 the program ends. When the user types in 1, 2, or 3 , the program displays the message.

  Create object-oriented design to enter name into text box

Create the object-oriented design for the system which permits the user to enter their name into the text box. When they press Go button message.

  Calculator to do the suitable matrix exponentiation

Every company makes particular restrictions for passwords, but employees of ABC have particularly strange restrictions. Their passwords may only consist of the lowercase letters

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