Java Programming:
Write a class called GNotes that:
- plays in order the notes G4, G5, G6, each for one and a half seconds
- The frequency of G4 is 392 Hz. Look up the other two.
import java.util.HashMap;
import stdlib.StdAudio;
public class GNotes {
public static void main(String[] args) {
HashMap<String, Double> frequencies = new HashMap<>();
frequencies.put("G4", 391.995);
frequencies.put("G5", 783.991);
frequencies.put("G6", 1567.98);
playNote(1.5, frequencies.get("G4"));
playNote(1.5, frequencies.get("G5"));
playNote(1.5, frequencies.get("G6"));
}
public static void playNote(double duration, double frequency) {
final int sliceCount = (int) (StdAudio.SAMPLE_RATE * duration);
final double[] slices = new double[sliceCount+1];
for (int i = 0; i <= sliceCount; i++) {
slices[i] += Math.sin(2 * Math.PI * i * frequency / StdAudio.SAMPLE_RATE);
}
StdAudio.play(slices);
}
}
In case of any doubts, please ask in comments. If the answer helps you, please upvote. I am in great need of upvotes. Thanks!
Java Programming: Write a class called GNotes that: - plays in order the notes G4, G5,...
In Java programming language. For this assignment, you must write a class Rectangle and a tester RectangleTest. The Rectangle class should have only the following public methods (you can add other non-public methods): Write a constructor that creates a rectangle using the x, y coordinates of its lower left corner, its width and its height in that order. Creating a rectangle with non-positive width or height should not be allowed, although x and y are allowed to be negative. Write...
Programming Language: Java 1. Write a class called Pair that stores a pair of numbers in private fields. Include a two-arg constructor, mutators and accessors. Override the equals method so that a Pair (1,2) would be considered equal to Pair (2,1). Write an appropriate toString method and make the toString method non-overrideable. 2. Write an interface called Comparable that includes a method isGreater, isLesser, and isSame. These methods should each take a Pair object as a parameter. 3. Write an...
This is a Java programming assignment and I want help with the Time class. See below for assignment details: For this question you must write a java class called Time and a client class called TimeClient. The partial Time class is given below. (For this assignment, you will have to submit 2 .java files: one for the Time class and the other one for the TimeClient class and 2 .class files associated with these .java files. So in total you...
For this question you must write a java class called Rectangle and a client class called RectangleClient. The partial Rectangle class is given below. (For this assignment, you will have to submit 2 .java files: one for the Rectangle class and the other one for the RectangleClient class and 2 .class files associated with these .java files. So in total you will be submitting 4 files for part b of this assignment.) // A Rectangle stores an (x, y) coordinate...
Data Structures and Algorithms (Java Programming) Write an insert function for a heap class as well as all support functions that are called by your insert function.
Java Programming assignment. 1. Create a class called Square that takes a width parameter in the constructor. The Square class should have a draw() method that will draw the square on the screen. Create a class called TestSquare that will take width from the user, create an object of Square, and invoke the draw() method on the square object. Below is a UML diagram for the Square and Rectangle class: 3. Create a zip file that contains your Java programs....
Write a JAVA program that plays a simple Pac-man game. The game plays on a 10 by 10 grid (absolutely, you can make it bigger). Pac-man is depicted as “#” and others as “*”. Please see the below. You should ask how many pac-man plays before starting the game. Then, you should create the number of pac-man objects. The pac-mans are defined as classes, and the objects are stored in an array. The pac-man class has a “move()” method, which...
In Java implement a class called Polynomials: This class should store the polynomial using a linked list with nodes. (do not use existing list classes in Java). This class should store only terms with non-zero coefficients. This class should store the polynomial terms in decreasing order of their powers. This class should have a constructor with no parameters that creates a polynomial with no terms, i.e. the polynomial 0. This class should have another constructor that takes a polynomial as...
Java programming. Introduction to Classes and Methods.
Please write the correct code, with comments so I can understand
what you did, and please make the code as SIMPLE as possible --
this is an intro to Classes/Methods practice. If your answer is
right, I will give you thumbs up rating!
Each of the following methods should be static and defined in a class called Utilities. Implement a second class calledTester that calls each of these methods
Using Java programming to answer this question. Write a method countLines(String inFilename) of a class FileUtility which reads a binary byte file with name inFilename using FileInputStream. The method returns the no. of lines containing comments starting with "//" with optional spaces (but not other characters) before it. Each line is terminated by '\n'. You may write other methods if necessary. Handle possible exception by outputting a suitable message if an exception occurs.