1 Replies - 326 Views - Last Post: 11 September 2019 - 01:54 AM Rate Topic: -----

#1 Roselyn18   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-September 19

Health Records Program using Encapsulation

Posted 10 September 2019 - 06:06 PM

Hello, I really could use help on an assignment to code a health record program to collect info on a patient that inputs data about themselves (name, birthday, height, weight etc.) then calculates their BMI and displays all the values in the main method. The programming requires it be be in two classes with input data as private variables using constructors to pass the info around and a main method to display all the values. Anything can be put in for String variables like their name, but for a number variable like age must be within a set range, and if the answer isn't in that range, the user will be prompted on loop until it is. Two methods are public, one to read values and the other to display them, and the setter and getter methods and the BMI calculation methods are private.

I only have this so far:


import java.util.Scanner;
import java.lang.Long;

class HealthRecord {
    
    private String firstName;
    private String lastName;
    private String email;
    private int age;  
    private long ssn;
    private double phoneNumber;
    private double weight;
    private double height;
    long phoneNum = 9999999999L;
    long socialS = 9999999999L;
    
    Scanner scan = new Scanner(System.in);

    
    public HealthRecord(String firstName2, String lastName2, String email2, int age2, long ssn2, double phoneNumber2, double weight2 , double height2) {
    
    firstName = firstName2;
    lastName = lastName2;
    email = email2;
    age = age2;
    ssn = ssn2;
    phoneNumber = phoneNumber2;
    weight = weight2;
    height = height2;

}
    
     private void setfirstName (String firstName2)  
    {
        System.out.println("Please enter your first name: ");
        firstName = scan.nextLine();
        firstName = firstName2;
    }

          private void setlastName (String lastName2)  
    { 
        System.out.println("Please enter your last name: ");
        lastName = scan.nextLine();
        lastName = lastName2;
    }

      private void setEmail (String email2)  
    { 
        System.out.println("Please enter your email: ");
        email = scan.nextLine();
        email = email2;
    }

            private void setAge(int age2) {
      
        System.out.println("Please enter your age from 1 to 125, (Ex. : 18) : ");
        age = scan.nextInt();
        
        while (age < 1 || age > 125)
        {
            System.out.println("Invalid input, please try again: ");
        }
        age = age2;
}

      private void setphoneNumber(long phoneNumber2)
              
      {
        System.out.println("Please enter your phone number (Ex. 6103258056) ");
        phoneNumber = scan.nextInt();
        
        while (phoneNumber < 1 || phoneNumber > phoneNum)
        {
            System.out.println("Invalid input, please try again: ");
        }
        
        phoneNumber = phoneNumber2;
      }

private void setWeight (double weight2)
        
      {
          System.out.println("Please enter your weight in pounds from 1 to 1400 (Ex 250) : ");
        weight = scan.nextDouble(); 
        
        while (weight < 1 || weight > 1400)
        {
            System.out.println("Invalid input, please try again: ");
        }
        weight = weight2;
      }

      private void setHeight (double height2)
      {
       System.out.println("Please enter your height in inches from 1 to 108 (Ex. 72): ");
       height = scan.nextDouble();
        while (height < 1 || height > 108)
        {
            System.out.println("Invalid input, please try again: ");
        }
        height = height2;
      }

      private void setSSN (long ssn2)
      {
       System.out.println("Please enter your SSN (Ex. 1867459824): ");
       ssn = scan.nextInt();
        while (ssn < 1 || ssn > socialS)
        {
            System.out.println("Invalid input, please try again: ");
        }
        ssn  = ssn2;
      }  
      
      
      public void readInputs () {
    
     
    
}

            
class HealthRecordDemo {
    
}

}




It's been hard to work with constructors, and trying to work at it for some time, only a small part off it is that I only think will work. And since the instructor requires students to only use Netbeans though we've only been working with BlueJay up until now, it makes coding even more complicated. So help would be very much appreciated here.

Is This A Good Question/Topic? 0
  • +

Replies To: Health Records Program using Encapsulation

#2 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3703
  • View blog
  • Posts: 16,976
  • Joined: 20-September 08

Re: Health Records Program using Encapsulation

Posted 11 September 2019 - 01:54 AM

It's not bad so far. Phone numbers are strings, not numbers. Also setters and getters follow a certain format. It's also unnecessary to invent different names for parameters to constructors

http://technojeeves....yle-conventions
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1