Java assignment needed urgent.

profileStudent_12345678
Assg3.zip

Assign03-student/Assign03-.docx

Assignment 03

(File I/O, Inheritance and Composition) 60 points

( Note: For all program questions, you must have appropriate comments, )

( the source code and screen-shot for your programs. )

Questions:

Qn1(20 points, 4 points each) Write a program including a runnable class and a test class “Assign3Qn1XX” to count the words in one or more files. Start a new thread for each file. For example, for files “my.txt”, “history.txt”, “Department.txt”, and “student.txt”, the program might print the following:

Department . txt : 221

student . txt : 184

history . txt : 280

my . txt : 192

Program snippet:

/**

*Countshowmanywordsinfiles.

*@ authorLastName,FirstName

*@ assignmentAssign 03 Qn 1

*@ dateDate

*/ publicclassLab 03 XX {

publicstaticvoidmain ( String argv []){ String [] list = {"my.txt",

"history.txt", "Department.txt", "student .txt"};

//addstatementsbelow

}

}

Qn2(20 points, 4 points each) Consider the following statements:

publicclassYClass

{

privateinta; privateintb;

publicvoidone ()

{

}

publicvoidtwo (intx,inty)

{

}

publicYClass ()

{

}

}

classXClassextendsYClass

{

privateintz;

publicvoidone ()

{

}

publicXClass ()

{

}

}

YClass y Object ; XClass x Object ;

(a) True or False? The private members of YClass are public members of XClass.

Explain why.

(b) Mark the following statements as valid or invalid. If a statement is invalid, explain why.

i. The following is a valid definition of the method one of YClass.

publicvoidone ()

{

System . out . println ( a + b);

}

ii. yObject.a = 15;

iii. xObject.b = 30;

iv. The following is a valid definition of the method one of XClass:

publicvoidone ()

{

a = 10;

b = 15;

z = 30;

System . out . println ( a + b + z);

}

v. System.out.println(yObject.a + ”” + yObject.b + ”” + xObject.z);

(c) Write the definition of the default constructor of YClass so that the instance variables of YClass are initialized to 0.

(d) Write the definition of the default constructor of XClass so that the instance variables of XClass are initialized to 0.

(e) Write the definition of the method two of YClass so that the instance variable a is initialized to the value of the first parameter of two and the instance variable b is initialized to the value of the second parameter of two.

Qn3(20 points, 5 points each)

Design various classes and write a program to computerize the billing system of a hospital by considering the following class:

/**

*Person.java

*/ publicclassPerson

{

privateString first Name ;//storethefirstname privateString last Name ;//storethelastname

//Defaultconstructor

//Initializefirst Nameandlast Nametoanemptystring. publicPerson ()

{

first Name =""; last Name ="";

}

//Constructorwithparameters

//Setfirst Nameandlast Nameaccordingtotheparameters. publicPerson ( String first , String last )

{

set Name ( first , last );

}

//Methodtooutputthefirstnameandlastname publicString to String ()

{

return( first Name +""+ last Name );

}

//Methodtosetfirst Nameandlast Nameaccordingtotheparameters. publicvoidset Name ( String first , String last )

{

first Name = first ; last Name = last ;

}

//Methodtoreturnfirst Name. publicString get First Name ()

{

returnfirst Name ;

}

//Methodtoreturnlast Name. publicString get Last Name ()

{

returnlast Name ;

}

}

(a) Design theclass Doctor, inherited from theclass Person with an additional data member to store a doctor’s specialty. Add appropriate constructors and methods to initialize, access, and manipulate the data members.

(b) Design theclass Bill with data members to store a patient’s ID and the patient’s hospital charges such as pharmacy charges for medicine, the doctor’s fee, and the room charges. Add appropriate constructors and methods to initialize, access, and manipulate the data members.

(c) Design theclass Patient, inherited from theclass Person with additional data members to store a patient’s ID, age, date of birth, attending physician’s name, the date when the patient was admitted in the hospital, and the date when the patient was discharged from the hospital. (Use theclass Date to store the date of birth, admit date, discharge date, and theclass Doctor to store the attending physician’s name.) Add appropriate constructors and methods to initialize, access, and manipulate the data members.

(d) Write a program to test your classes. Save the test file as Assign3Qn3FirstnameLastname.java, where Firstname and Lastname are your first name and last name respectively.

—————x———— Good Luck ————x————–

Assign03-student/Assign03Qn1XX.java

Assign03-student/Assign03Qn1XX.java

/**
 * Counts how many words in files.
 *  @author      Last Name, First Name
 *  @assignment  
 *  @date        Date
*/
public   class   Assign03Qn1XX   {
     public   static   void  main ( String  argv []){
         String []   list  =   { "my.txt" , "history.txt" ,   "Department.txt" , "student.txt" };
        
         //add statements below
           
     }
}

Assign03-student/Department.txt

akkkakakkkksjskkkdkkdkjfjfo oossknkjdjkjkfkkfjfkjgkjgjglgg goglglgmgkgkgkgkgkgjgkjg

Assign03-student/history.txt

kjbsajkgukehjbbdkhkcubdjkbdkhxdbkhcb jshkhlijdlkdkn khskhkjdj,dbjdbkjhldlkndldhlkdlkdbdkjbdk

Assign03-student/my.txt

kjsgyrbcxbc jgxihsknci udhnckjbsjkahjdjbduh dhjfbjkdhkjsbjbskjskuhjlkd

Assign03-student/Person.java

Assign03-student/Person.java


public   class   Person
{
     private   String  firstName ;   //store the first name
     private   String  lastName ;    //store the last name

         //Default constructor
         //Initialize firstName and lastName to an empty string.
         //Postcondition: firstName = ""; lastName = "";
     public   Person ()
     {
        firstName  =   "" ;
        lastName  =   "" ;

     }

         //Constructor with parameters
         //Set firstName and lastName according to the parameters.
         //Postcondition: firstName = first; lastName = last;
     public   Person ( String  first ,   String  last )
     {
        setName ( first ,  last );
     }

         //Method to output the first name and last name
         //in the form firstName lastName.
     public   String  toString ()
     {
         return   ( firstName  +   " "   +  lastName );
     }

         //Method to set firstName and lastName according to
         //the parameters.
         //Postcondition: firstName = first; lastName = last;
     public   void  setName ( String  first ,   String  last )
     {
        firstName  =  first ;
        lastName  =  last ;
     }

         //Method to return firstName.
         //Postcondition: The value of firstName is returned.
     public   String  getFirstName ()
     {
         return  firstName ;
     }

         //Method to return lastName.
         //Postcondition: The value of lastName is returned.
     public   String  getLastName ()
     {
         return  lastName ;
     }
}

Assign03-student/student.txt

shhufjkbjkfdkglkjsdjksdkhkjsdbkjdsfbs kdjvbjksdkjghskdjglksdglk ksndoijdaoijfaejfnsdjvzxb kzxhicvnsdkvdnkdsvhsdjvjsd sdhlsdjvbkddm vzjdgivsjg skfjvsjkfgdsthddva hv