Guitar Program with .txt filing
Java Code:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Console;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
class Yournamep3
{
boolean isTuned;
boolean isPlaying;
char [] GuitarStrings = {'E','A','D','G'};
public Yournamep3()
{
isTuned = false;
isPlaying = false;
}
public Yournamep3(boolean T, boolean P)
{
isTuned = T;
isPlaying = P;
}
public boolean playGuitar()
{
System.out.println("The Guitar is playing!");
return isPlaying = true;
}
public boolean stopPlaying()
{
System.out.println("The Guitar has stopped playing.");
return isPlaying = false;
}
public boolean tuneGuitar()
{
System.out.println("The
Guitar is being tuned!");
return
isTuned = true;
}
public static void main(String[] args) throws Exception
{
Yournamep3test
b=new Yournamep3test();
Yournamep3 a = new
Yournamep3();
System.out.println("Input
file Name: ");
Scanner in = new
Scanner(System.in);
String
fileNameInput = in.nextLine();
java.io.File file
= new java.io.File(fileNameInput+".txt");
java.io.PrintWriter output = new java.io.PrintWriter(file);
b.GuitarString("s",10);
System.out.println(b.getname());
System.out.println(b.getTunedValue());
System.out.println(a.playGuitar());
output.println(b.getname());
output.println(b.getTunedValue());
output.println(a.playGuitar());
output.close();
}
}
class Yournamep3test
{
private boolean isPlaying;
private int tunedValue;
private String name;
public void GuitarString(){
this.isPlaying = false;
this.tunedValue = 0;
this.name = "";
}
public void GuitarString(String
name){
this.isPlaying = false;
this.tunedValue = 0;
this.name = name;
}
public void GuitarString(String
name, int tunedValue){
this.isPlaying = false;
this.tunedValue = tunedValue;
this.name = name;
}
public boolean getisPlaying(){
return this.isPlaying;
}
public void setisPlaying(boolean isPlaying){
this.isPlaying = isPlaying;
}
public String getname(){
return this.name;
}
public void setName(String
name){
this.name= name;
}
public int getTunedValue(){
return this.tunedValue;
}
public void setTunedValue(int tunedValue){
this.tunedValue = tunedValue;
}
public void playNote(){
setisPlaying(true);
}
}
Class Diagram
Screenshots
No comments:
Post a Comment