Thanks for the support!
I have been working on a program with 7 classes, one the main and one starts the program, and I have been troubleshooting for a few hours trying to see why for one of the output constructors I'm not getting the classes to update the output. A class called OfficeVisit calls the class Appointment, which then calls the classes MyDate and MyTime to output their data input by the user back through OfficeVisit's output cosntructors. But I'm not getting the right output for some detail(s) that I can't find. While other classes that use MyDate and MyTime have no problem gathering data through them.
It's a program menu, this is the first class called by choosing option 3 from the menu, which calls Appointment, then Appointment calls MyDate and MyTime, then the user inputs data, but it not getting passed to the output for it):
package health.officevisit;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
import health.officevisit.MyDate;
import health.officevisit.MyTime;
public class OfficeVisit {
private MyDate DOB;
private MyTime TIME;
private int OfficeVisitId;
private Appointment AppmtId;
private Patient PatientID;
private double Temperature;
private int Pulse;
public OfficeVisit()
{
DOB=new MyDate();
TIME=new MyTime();
OfficeVisitId=000;
AppmtId=new Appointment();
PatientID=new Patient();
Temperature=00;
Pulse=00;
}
public MyDate GetDOB()
{
return DOB;
}
public MyTime GetTime()
{
return TIME;
}
public int GetOfficeVisitId()
{
return OfficeVisitId;
}
public Appointment GetAppmtId()
{
return AppmtId;
}
public Patient GetPatientId()
{
return PatientID;
}
public double GetTemperature()
{
return Temperature;
}
public int GetPulse()
{
return Pulse;
}
public void SetDOB(MyDate dob)
{
DOB=dob;
}
public void SetTime(MyTime time)
{
TIME=time;
}
public void SetOfficeVisitId(int officeVisitId)
{
OfficeVisitId=officeVisitId;
}
public void SetAppointmentId(Appointment appointmentId)
{
AppmtId=appointmentId;
}
public void SetPatientId(Patient patientId)
{
PatientID=patientId;
}
public void SetTemperature(double t)
{
Temperature=t;
}
public void SetPulse(int p)
{
Pulse=p;
}
public void Write(PrintStream ps)
{
String writeFile = "OffVRecord.txt";
try {
ps=new PrintStream(writeFile);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
ps.format("%02d/ %02d/ %4d\n", DOB.GetMonth(), DOB.GetDay(), DOB.GetYear());
ps.format("%02d: %02d: %02d:\n", TIME.GetHour(), TIME.GetMinute(), TIME.GetSecond());
ps.printf("%03d ", GetOfficeVisitId());
ps.printf("%05d \n", AppmtId.GetAppointmentId());
ps.printf("%04d \n", AppmtId.GetPatientId());
ps.printf("%4s %3d\n", GetTemperature(), GetPulse());
System.out.println("\nYour office visit has been created!");
System.out.println();
}
public void Read(Scanner s)
{
do {
System.out.println("Enter your office visit ID number (3 digit number): ");
while(!s.hasNextInt())
{
System.out.println("That's not an office ID number (only numbers please)!");
OfficeVisitId=s.nextInt();
}
OfficeVisitId=s.nextInt();
}while (OfficeVisitId <= 0);
SetOfficeVisitId(OfficeVisitId);
AppmtId.Read(s);
System.out.println("Enter your body temperature (decimals are accepted): ");
Temperature=s.nextDouble();
SetTemperature(Temperature);
System.out.println("Enter your blood pulse (3 digit number): ");
Pulse=s.nextInt();
SetPulse(Pulse);
}
}
package health.officevisit;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
import health.officevisit.MyDate;
import health.officevisit.MyTime;
public class Appointment {
private int AppointmentId;
private int PatientId;
private MyDate DOB2;
private MyTime Time2;
public Appointment()
{
AppointmentId=00000;
PatientId=0000;
DOB2=new MyDate();
Time2=new MyTime();
}
public Appointment(MyDate d, MyTime t, int appmtId, int PntId)
{
AppointmentId=appmtId;
PatientId=PntId;
DOB2=d;
Time2=t;
}
public void SetAppointmentId(int appointmentId)
{
AppointmentId=appointmentId;
}
public void SetPatientId(int patientId)
{
PatientId=patientId;
}
public void SetDate(MyDate d)
{
DOB2=d;
}
public void SetMyTime(MyTime t)
{
Time2=t;
}
public int GetAppointmentId()
{
return AppointmentId;
}
public int GetPatientId()
{
return PatientId;
}
public MyDate GetDate()
{
return DOB2;
}
public MyTime GetTime()
{
return Time2;
}
public void Read(Scanner s)
{
System.out.println("Enter your appointment ID number (5 number digits):");
AppointmentId=s.nextInt();
SetAppointmentId(AppointmentId);
System.out.println("Enter your Patient ID number (4 number digits):");
PatientId=s.nextInt();
SetPatientId(PatientId);
DOB2.Read(s);
Time2.Read(s);
}
public void Write(PrintStream ps)
{
String writeFile = "AppmtRecord.txt";
try {
ps=new PrintStream(writeFile);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
ps.printf("%05d %04d\n", GetAppointmentId(), GetPatientId());
ps.format("%02d/ %02d/ %4d\n", DOB2.GetMonth(), DOB2.GetDay(), DOB2.GetYear());
ps.format("%02d: %02d: %02d\n", Time2.GetHour(), Time2.GetMinute(), Time2.GetSecond());
System.out.println("Your appointment has been created!");
System.out.println();
}
}
package health.officevisit;
//*****************************************************************
//File: MyDate.java
//
//Purpose: this class declares the member variables, methods, and
// constructors that display a default value of parameters
// and fetch-in new values to a group of calendar date attributes.
//Written By:
//*****************************************************************
//import java.io.FileNotFoundException;
//import java.io.PrintStream;
import java.util.Scanner;
public class MyDate {
private int Month;
private int Day;
private int Year;
//*****************************************************************
//Method: MyDate
//
//Purpose: sets the member variables to default values
//*****************************************************************
public MyDate() //default constructor
{
Month=0;
Day=0;
Year=0000;
}
//*****************************************************************
//Method: MyDate(with the variable parameters)
//
//Purpose: receives the 3 variable instance passed from main method
//*****************************************************************
public MyDate(int m, int d, int y) //con
{
Month=m;
Day=d;
Year=y;
}
//*****************************************************************
//Method: GetMonth
//
//Purpose: returns the default month to the main method
//*****************************************************************
public int GetMonth()
{
return Month;
}
//*****************************************************************
//Method: GetDay
//
//Purpose: returns the default day to the main method
//*****************************************************************
public int GetDay()
{
return Day;
}
//*****************************************************************
//Method: GetYear
//
//Purpose: returns the default year to the main method
//*****************************************************************
public int GetYear()
{
return Year;
}
//*****************************************************************
//Method: SetMonth
//
//Purpose: sets the new month passed from main (the instance)
//*****************************************************************
public void SetMonth(int m)
{
Month=m;
}
//*****************************************************************
//Method: SetDay
//
//Purpose: sets the new day passed from main (the instance)
//*****************************************************************
public void SetDay(int d)
{
Day=d;
}
//*****************************************************************
//Method: SetYear
//
//Purpose: sets the new year passed from main (the instance)
//*****************************************************************
public void SetYear(int y)
{
Year=y;
}
//*****************************************************************
//Method: Read(with Scanner class as parameter)
//
//Purpose: reads-in the new date variables from the user
//*****************************************************************
public void Read(Scanner s)
{
System.out.println("Enter your Date of Birth. Enter the month (2 digits):");
Month=s.nextInt();
SetMonth(Month);
System.out.println("Enter the day (2 digits):");
Day=s.nextInt();
SetDay(Day);
System.out.println("Enter the year (4 digits):");
Year=s.nextInt();
SetYear(Year);
}
//*****************************************************************
//Method: Write(with PrintStream class method as parameter)
//
//Purpose: receives the PrintStream parameter called through
//the Read function from main and prints it out to the output file
//*****************************************************************
/*public void Write()
{
String writeFile = "Record.txt";
PrintStream ps;
try {
ps = new PrintStream(writeFile);
ps.format("%02d\t/%02d\t/%04d\n", GetMonth(), GetDay(), GetYear());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} */
}
package health.officevisit;
//*****************************************************************
//File: MyTime.java
//
//Purpose: this class declares the member variables, methods, and
// constructors that display a default value of parameters
// and fetch-in new values to a group of time attributes.
//Written By:
//*****************************************************************
//import java.io.PrintStream;
import java.util.Scanner;
public class MyTime {
private int Hour;
private int Minute;
private int Second;
//*****************************************************************
//Method: MyTime
//
//Purpose: sets the member variables to a default value
//*****************************************************************
public MyTime() //default constructor
{
Hour=00;
Minute=00;
Second=00;
}
//*****************************************************************
//Method: MyTime(with parameters)
//
//Purpose: receives the 3 variable instances passed from main method
//*****************************************************************
public MyTime(int h, int m, int s) //constructor that takes-in parameters
{
Hour=h;
Minute=m;
Second=s;
}
//*****************************************************************
//Method: GetHour
//
//Purpose: returns the default hour to the main method
//*****************************************************************
public int GetHour()
{
return Hour;
}
//*****************************************************************
//GetMinute
//
//Purpose: returns the default minute to the main method
//*****************************************************************
public int GetMinute()
{
return Minute;
}
//*****************************************************************
//Method: GetSecond
//
//Purpose: returns the default second to the main method
//*****************************************************************
public int GetSecond()
{
return Second;
}
//*****************************************************************
//Method: setHour
//
//Purpose: sets the new hour passed from main (the instance)
//*****************************************************************
public void SetHour(int h)
{
Hour=h;
}
//*****************************************************************
//Method: setMinute
//
//Purpose: sets the new minute passed from main (the instance)
//*****************************************************************
public void SetMinute(int m)
{
Minute=m;
}
//*****************************************************************
//Method: setSecond
//
//Purpose: sets the new second from main (the instance)
//*****************************************************************
public void SetSecond(int s)
{
Second=s;
}
//*****************************************************************
//Method: Read(with Scanner class as parameter)
//
//Purpose: reads-in the new time variables from the user
//*****************************************************************
public void Read(Scanner s)
{
System.out.println("Enter the time of your appointment. Enter the hour: ");
Hour=s.nextInt();
SetHour(Hour);
System.out.println("Enter the minutes: ");
Minute=s.nextInt();
SetMinute(Minute);
System.out.println("Enter the seconds: ");
Second=s.nextInt();
SetSecond(Second);
}
//*****************************************************************
//Method: Write(with PrintStream class method as parameter)
//
//Purpose: receives the PrintStream parameter called through
//the Read function from main and prints it out to the output file
//*****************************************************************
/*public void Write(PrintStream ps)
{
ps.format("%02d:\t %02d:\t %02d:\n", Hour, Minute, Second);
}*/
}
jg1405 0 Newbie Poster
Taywin 312 Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.