• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

new with java

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(System.in);
   // 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

1 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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now