• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating A Student Object, Replacing ID Number with Random Number  RSS feed

 
Greenhorn
Posts: 20
C++ Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I have pretty much laid the entire code out, reached like 95% completion on the project, and have done all that I can in terms of troubleshooting.

This code is the imports that are supplied for me to complete the assignment.

This little code snippet will explain the issue.

Alright, so it looks like it should work, right? Well, when Executing The Code, it still prompts me to type in an ID number. *Screenshots*
And here is the Result of that. Also, apparently the "exam scores" are not being placed in myStudent either..
Any suggestions?
 
Zachary House
Greenhorn
Posts: 20
C++ Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will also willingly admit that this is for a homework assignment, but I have actually put in a lot of effort, as opposed to some of the other posts I've seen asking for help with homework.

My apologies in advance if it is frowned upon to ask for general homework assistance from the CodeRanch.
 
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either the code you posted doesn't match the code you are compiling and running, or the constructor for Student is doing the prompting.
 
Zachary House
Greenhorn
Posts: 20
C++ Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can assure you that the code that is posted here is a direct copy and paste from the program itself. That would be just silly to seek help for code that you aren't even working with.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zachary House wrote:. . .. . .
It shou‍ld be easy enough to pass a “random” number to those variables.
num1 = ...;
Read this thread for explanation about why I think you shouldn't use Math#random to calculate such numbers, and what I think you shou‍ld use instead.
 
Zachary House
Greenhorn
Posts: 20
C++ Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read the thread through and through, and this is what I pulled from it:
- There are 2 ways to instantiate a random: the method I used, and Math.random()
It is entirely possible that I am completely lost too.

However, the code currently laid out is what was required by my instructor.
If you want, here are the instructions for the assignment.

I don't think I can just take a detour around what he asks for, despite him being more lenient than most college professors.
 
Zachary House
Greenhorn
Posts: 20
C++ Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know, I've been real stupid here. *GASP* "Humility?? That's a rare sight to see."
SO, I found the source of my error. The IDE kept running the entire program as a whole, and instead, the file itself needed to be run manually.
Needless to say, the output of this code is correct, and I did have the right code after all.
I apologize for wasting your time guys. On the bright side, I have successfully troubleshooted my own problem. How many Greenhorns can say that?   
 
Sheriff
Posts: 4935
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zachary House wrote:// num1, num2, and num3 are all "exam scores"
// I would have named them differently, if
// the current identifiers were not part of the instructions

you should name them properly. Nothing can be worse than agree to write poor names. You should go to instructor whoever gave this assignment and put your reasoning down, why you named them differently (clearly what they represent). The reason could be as simple as - "for the sake of clarity, so the code would be readable and maintainable".

If that is illegal, consider changing the course/university, so you wouldn't pay money for the bad practices they offer to you. Part of that is a package name "ProvidedClasses", which violates Java packages naming convention. That supposed to be "provided_classes".

If no one is complaining, very few people trying to improve something. So such practices floats on every cohort.
 
Liutauras Vilda
Sheriff
Posts: 4935
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even variable "name" isn't super clear. First name, last name, full name, middle name?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!