new with java

Posted on 2009-04-24
Last Modified: 2013-11-23
I have included the code I have created.  I am looking to get some guidance as to wether or not I accomplished what I set out to do.

I am trying to create a class that will allow me to enter a student number, credit hours and points earned.  

I then need to create a method to assign values to the fields.

Then   need to include a method to get a grade point average by dividing points by credit hours.

Finally I need to create a method to display the values.

I feel like I accomplished it all, except maybe the assigning values to each field.  And I only feel this way because I don't understand I guess.
import java.util.Scanner;

public class Student {

  public static void main(String[] args) {

   // Create a Scanner

   Scanner input = new Scanner(;

   // Enter Student ID Number

   System.out.print("Enter the student ID number: ");

   double studentNumber = input.nextDouble();

   // Enter Number of Credit Hours

   System.out.print("Enter the number of credit hours: ");

   double studentHours = input.nextDouble();

   // Enter Number of Points Earned

   System.out.print("Enter the number of points earned: ");

   double studentPoints = input.nextDouble();

   // Calculate GPA

   double studentAverage = studentPoints / studentHours;

   // Display Results

   System.out.println("Student number " + studentNumber + " earned " + studentHours + " credit hours and " + studentPoints +

   " resulting in a " + studentAverage + " GPA.");



Open in new window

Question by:lpetrowicz
    1 Comment
    LVL 2

    Accepted Solution

    I think that maybe you will need two classes Student and StudentCreator for example. The class you attached is pretty much Student Creator.

    Create a new class Student with the attributes ID, credit hours and points and generate the setter and getter methods for each attribute:

    public class Student {
      private double idNumber;
      private double creditHours;
      private double pointsEarned;

      public double getIdNumber() {
            return this.idNumber;
      public void setIdNumber(double idNumber) {
            this.idNumer = idNumber;

    // The same for the other attributes

    public double getAverage() {
                   double studentAverage = this.getPointsEarned() / this.getCreditHours();
                   return studentAverage ;

    public String getStudentInfo() {
                String strInfo = "ID: " + this.getIdNumber() + " Points: " + this.getPointsEarned()......;
                return strInfo;

    In StudentCreator create a new Student() and set the attributes
    Student myStudent = new Student();
    double studentPoints = input.nextDouble();

    And finally display the student info

    Hope you find this helpful
    Regards, Itzy

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now