[go: up one dir, main page]

0% found this document useful (0 votes)
216 views6 pages

Medicine Prescriptions Java

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

import java.util.

*;
public class CIS129_WhitneyHenderson_Lab3v2{
static Scanner keyboard = new Scanner(System.in);
static final int EXIT = 5;
static final String [][] MEDICINE = {
{"Abilify- ", "an antipsychotic drug"},
{"Ambien- ", "to treat insomnia"},
{"Amoxi- ", "an antibiotic"},
{"Aspirin- ", "a pain reliever"},
{"Crestor- ", "a cholesterol-lowering statin drug"},
{"Placebotec- ","to treat hypochondriacs"},
{"Xanax- ", "to treat anxiety disorders"},
{"Norvasc- ", "a high blood pressure drug"},
{"Penicillin- ","an antibiotic"},
{"Plavix- ", "a blood thinner"},
{"Prilosec- ", "to treat reflux disease"},
{"Wellbe- ", "an antidepressant"},
{"Nexium- ", "an antacid drug"},
{"Zoloft- ", "an antidepressant"}
};
public static void main (String [] args){
do{
boolean [] medsPrescribed = new boolean [MEDICINE.length];
int userInput;
String yourName;

displayWelcome();
menuOptions();
//makes sure that the first value entered is 1
userInput = getValidMenu("Please enter a menu option");
while (firstInput(userInput)){
System.out.println("You must sign in as a doctor first");
menuOptions();
userInput = getValidMenu("Please enter a menu option");
}// end while
yourName = IR.getString("Please enter your name Doc");

//makes ure that you are entering the correct values and searches the menu
menuOptionsDoc(yourName);
userInput = getValidMenu("Please enter a menu option");
searchMenu(userInput, medsPrescribed);
while(userInput != EXIT){
System.out.println("\n");
menuOptionsDoc(yourName);
userInput = getValidMenu("Please enter a menu option");
searchMenu(userInput, medsPrescribed);
}//end while
System.out.println("Goodbye");

}while(IR.getYorN("Would a new doctor like to sign in? (Enter yes or no)"));


}// end main
public static void displayWelcome(){

System.out.println("*************************************************************
***************************");
System.out.println("Welcome to the patient portal, a one stop shop to get your job done!");
System.out.println("Prescribe precriptions, check prescription history, and even reset the
prescription history");
System.out.println("Here are the menu options please sign in as a doctor first to get things
started!");

System.out.println("*************************************************************
***************************");
}
public static void menuOptions(){
System.out.println("*********************************************");
System.out.println("Welcome to Your Patient's Prescription History");
System.out.println("*********************************************");
System.out.println("Menu Options");
System.out.println("1. Sign in as the doctor");
System.out.println("2. Display prescription history");
System.out.println("3. Prescribe medicine");
System.out.println("4. Reset prescription history");
System.out.println("5. Exit the program");
}//end menu options 1

public static void menuOptionsDoc(String yourName){


System.out.println("*********************************************");
System.out.println("Welcome to Your Patient's Prescription History");
System.out.println("*********************************************");
System.out.println("Menu Options for Dr. " +yourName);
System.out.println("1. Sign in as the doctor");
System.out.println("2. Display prescription history");
System.out.println("3. Prescribe medicine");
System.out.println("4. Reset prescription history");
System.out.println("5. Exit the program");
}// end menuoptions2

// prints the main array


public static void print2Darray(String [][] MEDICINE){
for (int i = 0; i < MEDICINE.length; i++){
System.out.print("Medicine #"+(i+1)+":");
for (int j = 0; j < MEDICINE[i].length; j++){
System.out.print(MEDICINE[i][j]+" ");
}
System.out.println();
}
System.out.println("\n");
}
//initializes boolean array
public static void initBoolArr(boolean[] arr){
for (int i = 0; i < arr.length; i++){
arr[i] = false;
}// end for

}//end boolean intialize

//gets a number between 1-5 from the menu


public static int getValidMenu(String msg){
int userInput = IR.getInteger(msg);
while(isInvalid(userInput)){
System.out.println("Invalid value, please enter one of the menu options");
userInput = IR.getInteger(msg);
}
return userInput;
}//end getValidMenu

// makes sure first input is 1


public static boolean firstInput(int userInput){
if(userInput != 1){
return true;
}else{
return false;
}
}
//makes sure the user is entering the correct values 1-5
public static boolean isInvalid(int userInput){
if (userInput < 1){
return true;
}
if (userInput > 5){
return true;
}else{
return false;
}
}
//checks to see if the medicine prescribed is in the array
public static boolean isInArray(int userInput, boolean [] medsPrescribed){
if(medsPrescribed[userInput-1]){
return true;
}else{
return false;
}
}//end search array

//prescribes the medicine should this be a boolean?


public static void prescribe(int userInput, boolean [] medsPrescribed){
if(isInArray(userInput, medsPrescribed)){
System.out.println(MEDICINE[userInput-1][0]+MEDICINE[userInput-1][1]+" -already
prescribed");
}else{
medsPrescribed[userInput-1] = true;
System.out.println("You have prescribed "+MEDICINE[userInput-1]
[0]+MEDICINE[userInput-1][1]);
}
}

//search menu module. searches the menu when the user inputs
public static void searchMenu(int userInput, boolean [] medsPrescribed){
if(userInput == 2){
optionTwo(userInput, medsPrescribed);
}else{
if(userInput == 3){
userInput = optionThree(userInput);
if((IR.getYorN("Are you sure you would like to prescribe this medicine? (enter yes or
no)"))){
prescribe(userInput, medsPrescribed);
}
}else{
if(userInput == 4){
if((IR.getYorN("Are you sure you want to erase the precription history? (enter yes or
no)"))){
optionFour(userInput, medsPrescribed);
}
}else{
if(userInput == EXIT){
System.out.println(" ");
}
}
}
}
}// end searchMenu
//
//
//
//option three for entering the medicine they would like to prescribe
public static int optionThree(int userInput){
userInput = IR.getInteger("Please enter a menu option (enter 0 to see menu)");
if(userInput == 0){
print2Darray(MEDICINE);
}
while(validMenu(userInput)){
System.out.println("Enter one of the menu options please");
userInput = IR.getInteger("Please enter a menu option (enter 0 to see menu)");
if(userInput == 0){
print2Darray(MEDICINE);
}
}
return userInput;
}// end optionThree
public static void optionTwo(int userInput, boolean [] medsPrescribed){
System.out.println("************************************");
System.out.println("Your Patient's Prescription History");
System.out.println("************************************");
for (int i = 0; i < MEDICINE.length; i++){
System.out.print("Medicine #"+(i+1)+":");
for (int j = 0; j < MEDICINE[i].length; j++){
System.out.print(MEDICINE[i][j]);
}
if(medsPrescribed[i]){
System.out.print("-already prescribed");
}
System.out.println();
}
System.out.println("\n");
}

public static void optionFour(int userInput, boolean [] arr){


for (int i = 0; i < arr.length; i++){
arr[i] = false;
}// end for
System.out.println("Prescription history reset!");
}//end boolean intialize

//makes sure that the user enters a number 1-14


public static boolean validMenu(int menuChoice){
if(menuChoice < 1){
return true;
}
if(menuChoice > 14){
return true;
}else{
return false;
}
}// end valid menu

}// end program

You might also like