public class Procedure Properties private int procCode pr

public class Procedure {

//============ Properties =============
private int procCode;
private String procName;
private String procDesc;
private float cost;

//============ Constructors ===========
public Procedure(){
procCode = 0;
procName=\"\";
procDesc=\"\";
cost = 0.00f;
}
public Procedure(int c,String n,String d,float co){
procCode=c;
procName=n;
procDesc=d;
cost=co;
}

//=========== Behavior ==============
public void setProcCode(int c){procCode=c;}
public int getProcCode(){
return procCode;}

public void setProcName( String n){ procName = n;}
public String getProcName(){
return procName;}

public void setProcDesc(String d){procDesc =d;}
public String getProcDesc(){
return procDesc;}

public void setCost(float co){ cost=co;}
public float getCost(){
return cost;}

public void display(){

System.out.println(\"Procedure Code = P\"+getProcCode());
System.out.println(\"Procedure Name = \"+getProcName());
System.out.println(\"Procedure Discription = \"+getProcDesc());
System.out.println(\"Procedure Cost = \"+getCost());

}//end display()

public static void main(String args[]){

//Object 1
Procedure p1;
p1 = new Procedure(); //calls no argument constructor
p1.setProcCode(114);
p1.setProcName (\"Cleaning/Exam\");
p1.setProcDesc(\"Teeth Cleaning and a Dentist Exam\");
p1.setCost(99.99f);

p1.display();
  
System.out.println(\"\ \");//Space between 2 objects

//Object 2
Procedure p2;
p2 = new Procedure( 119, \"Xrays\", \"Teeth Whitening\", 320.00f);
//calls multi argument constructor
p2.display();

}//end main
}//end

Add a select method call select to read from the \"Procedures.text\"file using FileInputStream and Beffered reader. the File is delimited by \":\"(colon). Add a new method call insert to write to the file and add a new Procedure to the \"Procedures.text\" file using printStream and BufferedWriter.

Solution

Adding a method called select() to read the information from the \"Procedures.text\" file and added insert method to Write the contents to file Procedures.text using FileInputStream and Buffered reader as mentioned

public void select()

{

String line;

try{

InputStream fis = new FileInputStream(\"Procedures.text\"); // Reading the file to read the data from file

InputStreamReader fisr = new InputStreamReader(fis);

BufferedReader br = new BufferedReader(fisr); //Buffered readder is used

}

while((line =br.readLine())!=null) // reading line by line from the file

{

String[] str = line.split(\":\"); //way to split the file using delimeter and you can use \'str\' and can do operation as //you like

insert(line); // calling the new method Insert to write the records to file

}

}

public void insert(String str)

{

File file = new file(\"Procedures.text\"); // Opening a file to write the content.

if(!file.exists())

{

file.createNewfile();

}

FileWriter fw = new FileWriter(file.getAbsoluteFile());

BufferedWriter br = new BufferedWriter(fw);// Writing to the file using buffered reader.

br.write(line);

System.out.println(\"One Procedure is Written\ \");

}

public class Procedure { //============ Properties ============= private int procCode; private String procName; private String procDesc; private float cost; //=
public class Procedure { //============ Properties ============= private int procCode; private String procName; private String procDesc; private float cost; //=
public class Procedure { //============ Properties ============= private int procCode; private String procName; private String procDesc; private float cost; //=

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site