• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help for a school project

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone. I hope my problem is placed in the right forum...if not i apologize.  I will start with the beginning.
A few months ago I enrolled to a computer sciences school ( only three courses a week ) in the hope i would learn programming. ( Background info : I never did computers at school before but I am pretty good with html, css so i had a little knowledge about programmers in general but none about programming ). At school  in the 3 hours / week of object oriented programming I started to understand the basic principles of coding ...but at a very surface level. (plus i have almost zero time at home to study too much ) . All good so far but now I have to prepare the final assignment ( for tomorrow !!!) for which i have been trying to do in the past week but i got  stuck somewhere and i can t seem to be able to find a solution.
I will post here the assignment , the code i have been doing so far and my unsolved problems
(sorry again for the long post )

Assignment:
You have recently begun a position at Artetch Software Ltd as a Junior Programmer, and have joined a small development team to deliver a patient-doctor appointment system for a small local GP. Armstrong is a 24-hour GP surgery that currently caters to patients and operates outside of the NHS. The fee for an appointment is £100. Patients can pay a yearly fee of £1000, which is non-refundable if they do not fall ill and do not see a doctor in that year. The primary user of the application is the receptionist who is responsible for registering new patients, booking appointments and allocating a doctor to an appointment with a patient.
Currently, all registrations are completed manually by creating patient cards with unique patient ID numbers that the receptionist has to generate, which causes a problem in keeping track of ID numbers already in use.  The GP surgery would like the new system to register patients and book patients on an appointment to see a doctor. At times, some patients may wish to change the date of their appointment, so a feature to enable this should be provided in the final solution. When registering the patients, patients have the option to pay the full year’s fee upfront and if they do, they get a 10% discount. Bookings can only be made for the current day. No bookings should be made in advance. The user interface will be menu driven prompting the user to select a choice.
_______________________________________________________________________________

i am attaching the code as text    .first_project_java.txt  
my problem here is that i can not search for a patient or remove it. i know there is a remove method for arraylists but i can t seem to be able to make it work with my lists ( and taking user input - i would like to give user a choice to pick the number of the list to be able to delete it )

i am affraid i am using the arrylist wrong or i should use something else for what i need.

The other attachements are my other try on the code but got abbandoned becausse i couldn t make it register more than one patient.
All my code is a big soup with pieces put togheter from many sources so i appologise in advance for the stupid things in it.
All help would be appreciated.
Thanks guys

PS: i will attach in the next post 3 more files for the second project

PS2: i can t seem to be able to attach the code as text so i will be posting it as a reply to mu message
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raul Mihai wrote:All good so far but now I have to prepare the final assignment ( for tomorrow !!!) for which i have been trying to do in the past week but i got  stuck somewhere and i can t seem to be able to find a solution


Welcome to the Ranch!

Just so you're clear on what to expect from folks here, this is a volunteer site so people will answer as and when they are able to. That said, you'll get some responses fairly quickly if you come straight to the point, show only relevant snippets of code and describe your problem clearly. That is, describe what you were trying to do, show the code that you tried to do it with, what results you expected and what your actual results were.

 
Raul Mihai
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and the other 3 files. i hope i am attaching them
thanks again for any suggestion
 
Raul Mihai
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


______________________end of first post
 
Raul Mihai
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
----------------------the second part of the code

 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Afraid I can see things I don't like. I can't see any attempt to use objects anywhere. You aren't creating a Patient class anywhere. What you are doing is creating multiple parallel Lists, which is bad design and very error‑prone.
You also have marked all your methods static, which means they are outwith any objects.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raul Mihai wrote:my problem here is that i can not search for a patient or remove it. i know there is a remove method for arraylists but i can t seem to be able to make it work with my lists ( and taking user input - i would like to give user a choice to pick the number of the list to be able to delete it )


And I wrote:

come straight to the point, show only relevant snippets of code and describe your problem clearly. That is, describe what you were trying to do, show the code that you tried to do it with, what results you expected and what your actual results were.


I should have said the relevant code. (EDIT: I see that I actually did say "relevant" though) However, you showed us *all* your code, which isn't very helpful, especially with the distractions that come with all the other issues that jump out at people when they read your code.

Point out the parts of your code that you think are relevant to the problem you're asking about. Please don't make people wade through hundreds of lines of messy code to find your problem.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think deleting the patient's name from a List when there are multiple Lists in parallel is a disaster waiting to happen. Please have a look at my earlier post.
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a disaster waiting to happen. A 'Patient' class should be created to hold this info. Have one field in the Patient class for each of these attributes.
Now you only need a single list to keep track of. Note that 'static' really shouldn't be used here, see MainIsAPain.

 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:multiple Lists in parallel is a disaster waiting to happen.


Carey Brown wrote:This is a disaster waiting to happen


Waiting to happen? I think it's a full-blown disaster already when patient information is spread across multiple data structures like that. Now you have to synchronize all lists to make sure there's a 1:1 correspondence between one list and any and all of the other lists.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:.  . .  it's a full-blown disaster already . . . .

All right, then, OP will see what sort of disaster it is as soon as he tries to delete a name.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Based on the above attempt by OP, I think he/she needs to understand how List.add() and List.remove() work first.  In fact, the for-loop on line 119 will quickly terminate because the loop increment clause is x--.

@OP, why are you decrementing x in your for loop? That will cause an IndexOutOfBoundException when x becomes negative. And when you fix that, line 124 will also cause an IndexOutOfBoundsException to be thrown.

You need to understand why this happens.

Read the API documentation: https://docs.oracle.com/javase/8/docs/api/java/util/List.html#remove-int-
and go over the tutorial for lists: https://docs.oracle.com/javase/tutorial/collections/interfaces/list.html
 
Greenhorn
Posts: 28
Eclipse IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

At school  in the 3 hours / week of object oriented programming



I am new to Java and what I have read and what I have seen in your code is not "object oriented programming".  A good book will teach you that. Maybe even a bad book.  Can you get your money back if you paid for the course? I am no expert by any means. But really?
Best to you,
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steven Fraser wrote:. . . Can you get your money back . . .

No, but you will probably get away with it if you shoot the instructor and use that code as a defence: “provocation”
 
Greenhorn
Posts: 23
IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

...

This is a disaster waiting to happen. A 'Patient' class should be created to hold this info. Have one field in the Patient class for each of these attributes.



As side questions, and thinking a little bit ahead:

Data like this normally gets stored in databases (normalized into tables and fields), and I can certainly sense a "strong structural resemblance", so:

- Is it normal practice in Java to mirror tables into classes and fields into data variables?
- Is it a good pratice so that some back-end database system can then be utilized?

 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java classes can be used for rows in an SQL table and the fields in a class for columns.  An entire table might be List<MyClass>.
 
Ricky Bee
Greenhorn
Posts: 23
IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Java classes can be used for rows in an SQL table and the fields in a class for columns.  An entire table might be List<MyClass>.



Ok, I see. Each instance of the class will hold a set of values (as per field) that, together become a record, and the list is the "logical structured unit" to hold them objects together.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:...An entire table might be List<MyClass>.


Or a part of a table as returned by a query.
List<MyClass> results
As returned from a query "SELECT * FROM mytable WHERE something_is_true ORDER BY some_column"
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ricky Bee wrote:
- Is it normal practice in Java to mirror tables into classes and fields into data variables?
- Is it a good pratice so that some back-end database system can then be utilized?


I would say it's not uncommon. Whether or not it's a good practice depends.

See Object-Relational Impedance Mismatch
reply
    Bookmark Topic Watch Topic
  • New Topic