Question

In: Computer Science

I'm trying to get my code to loop back to let the user input multiple patients....

I'm trying to get my code to loop back to let the user input multiple patients.

import java.util.Scanner;

public class XYZ {

   public static void main(String[] args) {   
       String response;

       do{
           //import scanner for input
           Scanner input = new Scanner(System.in);   
           //prompt user input for last name
           System.out.print("Enter last name ");
           //output for last name
           String s1 = input.nextLine();
           //prompt user input for first name
           System.out.print("Enter first name ");
           //output for first name
           String s2 = input.nextLine();
           //prompt user for street address
           System.out.print("Enter street address ");
           //output for street address
           String address = input.nextLine();
           //prompt user for city
           System.out.print("Enter city ");
           //output for city
           String city = input.nextLine();
           //prompt user for state
           System.out.print("Enter state ");
           //output for state
           String state = input.nextLine();
           //prompt user for zipcode
           System.out.print("Enter zip code ");
           //output for zip code
           String zip = input.nextLine();
           //prompt user for owed amount
           System.out.print("Enter amount owed ");
           //output for amount owed
           String amount = input.nextLine();
           //prompt user for payment amount
           System.out.print("Enter payment amount ");
           //output for payment amount
           String payment = input.nextLine();
           //prompt user for payment date
           System.out.print("Enter payment date ");
           //output for payment date
           String date = input.nextLine();

          


       //final print out output title
       System.out.printf("%80s\n", "XYZ Community Hospital");
       //final print out spacing
       System.out.printf(String.format("%150s\n", "").replace(' ', '='));
       //final print out titles and spacing
       System.out.printf("%10s%30s%80s\n", "Name", "Address", "Payment Information");
       //final print out titles and spacing
       System.out.printf("%-8s %-12s %-30s %-15s %-5s %-10s %-15s %-15s %-15s \n", "Last", "First", "Address Line 1", "City", "State", "Zip", "Amount Owed",

               "Payment Amt.", "Payment Date");

       System.out.printf(String.format("%150s\n", "").replace(' ', '='));
       //final output print out
       System.out.printf("%-8s %-12s %-30s %-15s %-5s %-10s %-15s %-15s %-15s \n", s1, s2, address, city, state, zip, amount, payment, date);

       //ask user for next entry
       System.out.println("Would you like to make another entry?[Y/N]");
       response = input.nextLine();
       input.close();
   }
   while (response==("Y")); }

      
  
   }

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________


// XYZ.java

import java.util.Scanner;

public class XYZ {

   public static void main(String[] args) {   
   String response;
   Scanner input=null;
   do{
   //import scanner for input
   input = new Scanner(System.in);   
   //prompt user input for last name
   System.out.print("Enter last name ");
   //output for last name
   String s1 = input.nextLine();
   //prompt user input for first name
   System.out.print("Enter first name ");
   //output for first name
   String s2 = input.nextLine();
   //prompt user for street address
   System.out.print("Enter street address ");
   //output for street address
   String address = input.nextLine();
   //prompt user for city
   System.out.print("Enter city ");
   //output for city
   String city = input.nextLine();
   //prompt user for state
   System.out.print("Enter state ");
   //output for state
   String state = input.nextLine();
   //prompt user for zipcode
   System.out.print("Enter zip code ");
   //output for zip code
   String zip = input.nextLine();
   //prompt user for owed amount
   System.out.print("Enter amount owed ");
   //output for amount owed
   String amount = input.nextLine();
   //prompt user for payment amount
   System.out.print("Enter payment amount ");
   //output for payment amount
   String payment = input.nextLine();
   //prompt user for payment date
   System.out.print("Enter payment date ");
   //output for payment date
   String date = input.nextLine();

  


   //final print out output title
   System.out.printf("%80s\n", "XYZ Community Hospital");
   //final print out spacing
   System.out.printf(String.format("%150s\n", "").replace(' ', '='));
   //final print out titles and spacing
   System.out.printf("%10s%30s%80s\n", "Name", "Address", "Payment Information");
   //final print out titles and spacing
   System.out.printf("%-8s %-12s %-30s %-15s %-5s %-10s %-15s %-15s %-15s \n", "Last", "First", "Address Line 1", "City", "State", "Zip", "Amount Owed",

   "Payment Amt.", "Payment Date");

   System.out.printf(String.format("%150s\n", "").replace(' ', '='));
   //final output print out
   System.out.printf("%-8s %-12s %-30s %-15s %-5s %-10s %-15s %-15s %-15s \n", s1, s2, address, city, state, zip, amount, payment, date);

   //ask user for next entry
   System.out.println("Would you like to make another entry?[Y/N]");
   response = input.nextLine();
     
   }
   while (response.equalsIgnoreCase("Y"));
   input.close();
   }

   }
_________________________

Output:

Enter last name Faulkner
Enter first name James
Enter street address 101 Church Street
Enter city Banglore
Enter state Karnataka
Enter zip code 560068
Enter amount owed 5000
Enter payment amount 45000
Enter payment date 12/12/2019
XYZ Community Hospital
======================================================================================================================================================
Name Address Payment Information
Last First Address Line 1 City State Zip Amount Owed Payment Amt. Payment Date
======================================================================================================================================================
Faulkner James 101 Church Street Banglore Karnataka 560068 5000 45000 12/12/2019
Would you like to make another entry?[Y/N]
y
Enter last name Roy
Enter first name Rahul
Enter street address 2nd Lake View Street
Enter city Banglore
Enter state Karnataka
Enter zip code 560037
Enter amount owed 2300
Enter payment amount 17000
Enter payment date 12/11/2019
XYZ Community Hospital
======================================================================================================================================================
Name Address Payment Information
Last First Address Line 1 City State Zip Amount Owed Payment Amt. Payment Date
======================================================================================================================================================
Roy Rahul 2nd Lake View Street Banglore Karnataka 560037 2300 17000 12/11/2019
Would you like to make another entry?[Y/N]
n

________________________

Mistakes You have done :

1) You close the scanner inside the loop.

2) We cant compare the two Strings objects using double equal (==) method.Since response variable is of type string we have to use equals() method or equalsIgnoreCase() method

_______________Could you plz rate me well.Thank You


Related Solutions

I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
Javascript array of objects: I'm trying to get the input into an array of objects, and...
Javascript array of objects: I'm trying to get the input into an array of objects, and then display the information in a table using a for loop, but I don't think my path is right <!DOCTYPE html> <head> <title>Form</title> <meta charset="utf-8" /> <style media="screen"> h1 { text-align: center; } div { background-color: #pink; border: 2px solid green; padding: 15px; margin: 65px; } </style> <script> var list = []; total = 0; text = ""; function Product(item, quantity, costs){ this.item =...
I'm trying to get the union of two arrays and I tried making a loop that...
I'm trying to get the union of two arrays and I tried making a loop that does so. I tried also making the loop give me the size of the array as well from the union of the two arrays. Please check my loop to see what is wrong with it because it is not doing what I want it to do. I'm also not sure how to get the correct size of the array after the two arrays have...
Trying to score a hand of blackjack in this python code but my loop is consistently...
Trying to score a hand of blackjack in this python code but my loop is consistently outputting (13,1) which makes me think that something is wrong with my loop. Could someone help me with this code?: import random cards = [random.randint(1,13) for i in range(0,2)] #initialize hand with two random cards def get_card(): #this function will randomly return a card with the value between 1 and 13 return random.randint(1,13) def score(cards): stand_on_value = 0 soft_ace = 0 for i in...
Invalid entry code in python my code is pasted below. The last elif statement, I'm trying...
Invalid entry code in python my code is pasted below. The last elif statement, I'm trying to get the program to print "invalid entry" if the entry for user_input is invalid. The first user prompt should only allow for numbers 1-10 and "exit" and "quit" import math user_prompt = """Enter number of operation that you want to execute <type exit or quit to end program>: 1 sin(x) 2 cos(x) 3 tan(x) 4 asin(x) 5 acos(x) 6 atan(x) 7 ln(x) 8...
XML and XSL I'm trying to style my XML code but it's not implementing the XSL...
XML and XSL I'm trying to style my XML code but it's not implementing the XSL file when I run it even though the file is referenced. Any help? XML code: <?xml version="1.0"?> <?xml-stylesheet href="textbooks.xsl" type="text/xsl" ?> <textbooks> <textbook> <title> Introduction to Design and Analysis of Algorithms</title> <authors> <author> <firstName>Anany</firstName> <lastName>Levitin</lastName> </author> </authors> <publisher> <name>Ed, Pearson</name> <website>https://www.pearson.com</website> </publisher> <Year-of-Publication>2011</Year-of-Publication> <ISBN>978-0132316811</ISBN> <book-specific-website></book-specific-website> <edition>3rd edition</edition> <cover-type>Paperback</cover-type> </textbook> <textbook> <title>Software Engineering: A Practitioner’s Approach</title> <authors> <author> <firstName>Roger</firstName> <lastName>Pressman</lastName> </author> </authors> <publisher> <name>Ed, McGraw-Hill</name>...
So, I'm trying to get an average revolutions/minute from an input vector. Here's a sample vector:...
So, I'm trying to get an average revolutions/minute from an input vector. Here's a sample vector: V=[10200 11000 11800 12300 13100 13900 14400 15020 15850 16250] The units are in ms so 10200 is 10.2 seconds. The revolutions is between every successive value. So 11000 - 10200 is 1 revolutions per 800 ms and et cetera. I need help figuring out a code that will allow me find the average cadence from the whole dataset. Thank you in advance
So, I'm trying to get revolutions/second from a given binary data. for example, the input binary...
So, I'm trying to get revolutions/second from a given binary data. for example, the input binary data is: V=[0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 1 0 ] let's say the distance between each value is arbitrary (for this example, you can use 0.1). Each 1 represents a full rotation of a bike pedal, and I'm trying to calculate the pedal rate from a given binary dataset in Matlab. How...
Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
I'm having difficulty trying to make my code work. Create a subclass of Phone called SmartPhone....
I'm having difficulty trying to make my code work. Create a subclass of Phone called SmartPhone. Make this subclass have a no-arg constructor and a constructor that takes a name, email, and phone. Override the toString method to return the required output. Given Files: public class Demo1 { public static void test(Phone p) { System.out.println("Getter test:"); System.out.println(p.getName()); System.out.println(p.getNumber()); } public static void main(String[] args) { Phone test1 = new SmartPhone(); Phone test2 = new SmartPhone("Alice", "8059226966", "[email protected]"); System.out.println(test1); System.out.println(test2); System.out.println(test1);...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT