Assign03-student/Assign03- x
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
We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.
Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.
Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.
Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.
Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.
Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.
We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.
Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.
You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.
Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.
Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.
You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.
You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.
Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.
We create perfect papers according to the guidelines.
We seamlessly edit out errors from your papers.
We thoroughly read your final draft to identify errors.
Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!
Dedication. Quality. Commitment. Punctuality
Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.
We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.
We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.
We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.
We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.