Computer Science Homework Solutions
Problem
#4175

Writing a program in java.

Sorry I was a little vague earlier, I really wasn't sure what I wanted! Please look at my program so far and see if it is even slightly correct.

I would really like to know
1. the window objects I should have
2. the instance variables I should have
3. how many classes I should have and what are they?
Particular questions I have are
1. How do I make the number of beds in the ward a constant? Where can the user input the number of beds?
2. How do I make a circular array of this number?
3. How do I make the patient details strings? And what is information hiding on strings? Where does it hide? How do I do that?
4. How do I make text appear in the text area?Neatly.
5. How do I remove a patient?

A copy of another similar programs code would be great if you have one so I can see how it all goes together.

I would like as much help as possible with this. Basically I'm after a crashcourse in Java and how to put it together.

I would find it a lot easier if I could see it working. I have no examples of programs here to look at. If you can't show me the whole program, can you show me the main bits of code?

Attached file(s):
Attachments
SENGASGNMENT2.doc  View File
ASSIGNMENT2.txt  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

SENGASGNMENT2.doc
Scenario

A hospital has asked you to write a program to keep track of the
patients in its wards. Each ward will have its own copy of the software,
so the program is only required to deal with a single ward. The name of
the driver program should be ProgAsgn2.

Patients

A patient object consists of name, date of birth, date of admission,
treating doctor and diagnosis; for the purposes of this assignment, all
of these can be Strings. (Admission is when a patient is accepted into
the ward and discharge is when the patient is permitted to leave.) Your
program should include a class that models an individual patient. Your
patient model should implement information hiding, allowing access to
instance data only through appropriate accessor and mutator methods.

The Ward

Another class will then establish and work with an array of as many
patient objects as there are beds in the ward (it would make sense to
store this number as a constant). This class will effectively be a model
of the ward. Unoccupied beds will be represented as null. The ward
should also follow information hiding principles.

The GUI

The program should work by way of a GUI that has a title, text fields
for the details of the current patient, five buttons, and a text area
for display of the occupied beds and the patients occupying them. Each
of these is described below.

The title of the GUI should be a suitable one of your own choosing.

At any given time one of the patients will be the ‘current’ patient.
That patient’s details, along with the patient’s bed number, will be
displayed in the GUI’s text fields. Any details displayed in those
fields can be edited, and the changes will be registered when any of the
buttons is pressed. If no beds are occupied, there will be no current
patient, and the text fields should be blank.

At the same time, the details of all occupied beds and their patients
will be displayed in the text area. If two beds are occupied, two lines
of data will appear in the text area; if 17 beds are occupied, 17 lines
of data will appear in that area.

The New patient button should clear the text fields so that the details
of a new patient can be entered, except that if all beds are occupied,
the user should be informed that no further admissions are possible.
Once the New Patient button has been selected and the new patient data
entered, it is expected that the next button selected will be Admit
Patient, otherwise a message box should be displayed saying that the
information entered has been lost.

The Admit Patient button should use the contents of the text fields to
create a new patient in the indicated bed, except that if the indicated
bed number represents an occupied bed, the user should be invited to
enter the number of an unoccupied bed and try again. A successful
admission should be indicated with a message box.

The Discharge Patient button should generate a suitable message and
remove the current patient from the display. The next occupied bed will
then become the current one.

The Next Patient and Previous Patient buttons should move to the next
occupied bed and the previous occupied bed respectively, making the
occupant of that bed the current patient and displaying that patient’s
details in the text fields. From the point of view of these buttons, the
ward is a ‘circular’ arrangement; in a 12-bed ward, the ‘Next’
bed to bed 12 is bed 1 and the ‘Previous’ bed to bed 1 is bed 12.
Because the user can edit the details of the current patient, these
should be updated from the text fields before moving on.
ASSIGNMENT2.txt
import javax.swing.*;
import BreezySwing.*;

public class ProgAsgn2 extends GBFrame{

//Window objects

Jlabel nameLabel = addLabel("Name:",3,3,1,1);
JLabel birthLabel = addLabel("Date of Birth:",4,3,1,1);
JLabel admitLabel = addLabel("Admission Date:",5,3,1,1);
JLabel doctorLabel = addLabel("Treating Doctor:",6,3,1,1);
JLabel diagnosisLabel = addLabel("Diagnosis:",8,3,1,1);
JLabel bedLabel = addLabel("Bed Number:",1,3,1,1);
JLabel bedsInWardLabel = addLabel("Number of Beds In Ward:",17,1,2,1);

JButton newButton = addButton("New Patient",3,5,1,1);
JButton admitButton = addButton("Admit Patient",6,5,1,1);
JButton dischargeButton = addButton("Discharge Patient",9,5,1,1);
JButton previousButton = addButton("<< JButton nextButton = addButton("Next>>>",15,5,1,1);

JTextField nameTextField = addTextField(" ",3,4,1,1);
JTextField birthTextField = addTextField(" ",4,4,1,1);
JTextField admitTextField = addTextField(" ",5,4,1,1);
JTextField doctorTextField = addTextField(" ",6,4,1,1);

JTextArea diagnosisTextArea = addTextArea(" ",9,3,2,7);
JTextArea bedsTextArea = addTextArea(" ",1,1,2,16);

IntegerField bedNumberIntegerField = addIntegerField(" ",1,4,1,1);
IntegerField bedsInWardIntegerField = addIntegerField(0,17,2,1,1);

//Other instance variables
int bed; //bed number
int patient; //patient number
int bedsInWard; //number of beds in ward

private int indexSelectedPatient;
private int patientCount;

//Constructor

public ProgAsgn2(){
setTitle("Patient Database--Version 1");

indexSelectedPatient=1;
patientCount=0;

displayCurrentPatient();
}

//buttonClicked method

public void buttonClicked(JButton buttonObj){
if(buttonObj == newButton){
newPatient();
}else{
if(buttonObj == admitButton){
admitPatient();
}else{
if(buttonObj == dischargeButton){
dischargePatient();
}else{
if(buttonObj == previousButton){
displayPreviousPatient();
}else{
if(buttonObj == nextButton){
displayNextPatient();
}

//private methods

private void newPatient(){
int bedsInWard=bedsInWardIntegerField.getNumber();
if(int bedsInWard == 0){
messageBox("Please enter number of beds in ward");
return;
}else{
if(!int bedsInWard.isValid()){
messageBox("Sorry:The number of beds must be an integer.";
return;
}else{
if(int bedsInWard.isValid()){
resetAllFields();

if buttonObj == admitButton){
admitPatient();
}else{
messageBox("Admission not complete.Details will be lost unless admitted.";
return;
}


private void resetAllFields(){
nameTextField.setText(" ");
birthTextField.setText(" ");
admitTextField.setText(" ");
doctorTextField.setText(" ");
diagnosisTextArea.setText(" ");
bedsInWardIntegerField.setNumber(" ");
}


Solution
What is this?
By OTA - Overall OTA Rating
Jamshed Dastur, MSc (IP) - n/a
Purchase Cost Now
$2.19 CAD (was ~$39.90)
Included in Download
  • Plain text response
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • HELP WITH THESE THREE QUESTIONS - 1. Why declaration of a variable is considered to be an important (and sometimes required) part of good programming practice? 2. Name few languages that allow use of variables without even declari ...
  • Programming Concepts - Define and study the terms "variable" and "constant" as used in computer programming. Determine the various types of data (such as char, int, double, string, and date) that can be used in developing a ...
  • Session Variables - What is a Session variable? How can Session variables be used in an online Banking application?
  • Session Variables in a web application - When should a developer use Session variables in a web application? How can a Session variable affect the scalability of a web application?
  • Variables, prompts, pseudocode, and flowcharts. - Start Declare Testscore as integer Write "Enter your Test Score and Your Grade will be displayed" INPUT Test score IF TestScore > 90 Write "Your Grade is an A" Else If TestScore > 80 ...
Browse