Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Help creating an sorting program with pictures

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

I need to create a program that helps an church organize it's members using gender and age.

For example, for someone greater than or equal to 0 but less than 12, regardless of gender, display the words: You go to Primary! in the program window. Display the Rock Chapel image.
For a female ages 12 and 13, display the words You belong to the Young Women 12–13 class and show their image.
For a male ages 12 and 13, display the words You belong to the Young Men 12–13 class and show their image.

This process repeats for 14-15, 16-17, and 18-121.
I have images for 0-12M/F, 12-13F, 14-15F, 16-17F, 18-121F, 12-13M, 14-15M, 16-17M, 18-121M. Anything else is an error code.

I think I have the basics of the program, but I don't know how to include multiple images using JPanel. I also don't know how to set up both an male and female input on the program. If somebody could give me some pointers that would be awesome!
My code is below. I have // notes to where I think the problem is.

 
Marshal
Posts: 70696
288
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's paintComponent() not printComponnt(). How did you get that to compile? It has lots of other compiler errors in. Please read this. What's more, we can't tell how many of the logic errors you showed are caused by bad copying and how many are “real”.

Don't use display components to do business logic. Do that in another class. You can create SundaySchoolClass (=SSC) objects that record age ranges, gender, and have an attached picture. You can even pass Worshipper objects to a collection of SSC objects and let the SSC object pick their constituents.
 
John Noneya
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Attached is my full and fixed code. The image files are in the same folder. My biggest issue right now: I have no idea how to incorporate gender. I know that the  "if gender = f{" and "if gender = m{" lines that I used in my code don't work, they're really just there to as a note to me that I need to find a way to fix it. If anybody could help me out a little bit, that would be huge! Thank you so much.


 
John Noneya
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please ignore my previous code. There were some compile errors I fixed. Below is the new code. The only errors are with the male/female lines, which makes sense because they're useless lines. I still don't know how to tell the program how to split male/female.
 
Rancher
Posts: 218
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using improper String comparisons.

Strings are an object type, which is different from a native type like an int. For any Object type, the "==" operator compares the address of the object, not the contents of the object. This matters, because when you compare gender to "m", you are creating a new String which contains the letter "m", and comparing it to an existing String which contains the letter "m". They are not equal, since they don't have the same address.

You have a comment in your code on your line that assigns gender that tells you the way to fix this. Specifically, you need to compare the Strings in a way that compares the contents instead of the address (you can use .equalsIgnoreCase)

Also a general comment - all those variables you use should be private. You also don't need to load the actual image until the user needs to see that image - though this is more of an efficiency concern that won't matter for such a small application.
 
John Noneya
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zachary Griggs wrote:
You have a comment in your code on your line that assigns gender that tells you the way to fix this. Specifically, you need to compare the Strings in a way that compares the contents instead of the address (you can use .equalsIgnoreCase)



Could I use something like this then?
 
Saloon Keeper
Posts: 7395
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Campbell Ritchie
Marshal
Posts: 70696
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That if‑else will fall down horribly when somebody pushes N because of fat‑finger (N is next to M) or MM for M.
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic