Join Peggy Fisher for an in-depth discussion in this video Solution: Hospital stay, part of Learning Java.
- I hope you had fun with this last challenge.…The challenge was meant to get you started…with adding decision-making logic,…loops, and optionally, methods.…Let's take a look at my solution.…Remember that your solution might be very different.…There are a few lines of code that will be new,…but I think it will help you understand…how you can expand on the information…I've already provided.…Let's walk through the code.…In the main method, I start by declaring variables…that I'll need for both an in-hospital…and outpatient stay.…
I have medication charges, lab service charges,…hospital charges, and then total cost.…I added a string variable called "response."…This will allow me to ask the user…if they have another patient.…If they do, I'll run through the loop again.…Otherwise, I'll exit.…In my solution, I use a do-while loop.…I say, "Do."…The first thing I do is check to see…if it's an overnight stay.…I created a method for this, but you wouldn't have to.…Let's take a look at the method real quick.…It returns a Boolean variable…
- Downloading and exploring NetBeans
- Understanding Java basics: data types, strings, arrays, and more
- Controlling flow with functions and loops
- Creating classes
- Sorting and searching arrays
- Manipulating files
- Handling errors
- Building GUIs
Skill Level Beginner
1. Getting Started
2. Java Basics
3. Flow of Control
4. Classes and Objects
5. Beyond the Basics
6. File Manipulation
7. Graphical User Interface Basics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.