• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Trying to format object array

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to format the output where the name will occupy 25 columns and the GPA will occupy 10 and be displayed with one digit of precision in the system console in addition to outputting each student info in a message dialogue box. I am also trying to generate a random that will chose information for a student to be excused for a final exam and output it to the console.




 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting your code.

I must ask why would you "mix" your application, so part of it uses Swing and part of it interacts with user over console? That's very bad approach in this case. Either choose first one and develop GUI application, or another and interact with user over console.

First of all, your default constructor in Student class is wrong. You are just declaring new variables (though with the same name as class fields) that are local to the constructor block, and your fields are left uninitialized.
On the other hand, to achieve output formatted as you want it to be, take a look at this tutorial. Also, check the API of Random class that you need for your last requirement.

Edit: And welcome to the Ranch!
 
Marshal
Posts: 76884
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree with KS. I would say you ought to get rid of that no‑arguments constructor altogether. There is no such thing as a Student called Last. First, and even if there were they would never get a 4.0gpa. So you don’t want that constructor. You want to insist every Student have a name and gpa? All, right, only supply a constructor which takes name and gpa parameters.
And welcome again

I added code tags, which makes your code look a lot better, but highlights some indenting mistakes. Remind yourself about how to indent here or here (but not both; they are not mutually compatible).
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic