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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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