How do I pass these variables to calculate a new GPA in my class?

CrypticZero

sorry for this very similar question to my last post, but I'm having a slightly different problem to my last question. I have gotten everything to compile and work in my project, but I am not sure how to calculate a new gpa for student1 and student2 in my class by passing a total amount of points and a total amount of classes. My teacher wants us to calculate student1's gpa by passing 40 total points for 7 classes and to calculate student2's gpa by passing 36 total points for 8 classes. Like I said, the rest of my code works, I'm just not sure how to do this yet as I'm still fairly new to coding. The answer is probably pretty simple, but I can't figure it out for the life of me. Here is my code:

public class student
{
   private String name;
   private int year;
   private int age;
   private double gpa;
   /*
    * Default Constructor
    */
   public student()
   {
       name = "John";
       year = 2016;
       age = 16;
       gpa = 4.0;
   }
   /* 
    * other constructor
    */
   public student(String name, int year, int age, double gpa)
   {
       this.name = name;
       this.year = year;
       this.age = age;
       this.gpa = gpa;
   }
   /*
    * accessors
    */
   public String getName()
   {
       return name; 
   }
   public int getAge()
   {
       return age;
   }
   public int getYear()
   {
       return year;
   }
   public double getGpa()
   {
       return gpa;
   }
   /*
    * mutators
    */
   public void setName(String name)
   {
       this.name=name;
   }
   public void setGpa(double gpa)
   {
       this.gpa=gpa;
   }
   public void setYear(int year)
   {
       this.year=year;
   }
   public void setAge(int age)
   {
       this.age=age;
   }
   /*
    * calculate GPA
    */
   public double calcGpa(double points, int classes)
   {
      gpa = points / classes;       
      return gpa; 
   }
   public String toString() 
   {
    return name + year + age + gpa;
   }
}



public class studentReal
    {
       public static void main(String[] args)
       {
           student student1= new student("Jackie Java", 2018, 16, 4.7);
           student student2= new student("John Java", 2019, 15, 3.8);
           student student3= new student();
           System.out.println(student1.getName() + ", class " + student1.getYear()+ ", " + student1.getAge() + ", " + student1.getGpa());
           System.out.println(student2.getName() + ", class " + student2.getYear()+ ", " + student2.getAge() + ", " + student2.getGpa());
           System.out.println(student3.getName() + ", class " + student3.getYear()+ ", " + student3.getAge() + ", " + student3.getGpa());
       }
    }
outrunengineer

In your studentReal class, inside the main method, use the calcGpa method you created within the Student class, for each student. The method, just like the variables, belongs to that student.

For example:

    student1.calcGpa(40, 7);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I use toString to retrieve my information in my class and how do I get my method to calculate the "GPA" in this class?

From Dev

how do i transfer this form.cs code in my new class calculate?

From Dev

How do I pass variables into my class, ID, or data attribute in RiotJS?

From Dev

How do i pass my scope correctly to look for variables

From Dev

How to calculate a sum from my class variables?

From Dev

How do i pass the Label4.Text to a new class?

From Dev

How do I override `toString` in my derived class and use the private instance variables from the base class?

From Dev

How do I pass variables to a jQuery function?

From Dev

How do I pass variables around in Python?

From Dev

how do I pass variables to angularjs factories

From Dev

How do I pass environment variables to babelrc?

From Dev

How do I pass node.js server variables into my angular/html view?

From Dev

Trying to add a partial form to my index page. How do I pass multiple variables to generate the form?

From Dev

VB 13 windows form - how do I pass my variable between two forms [New to coding]

From Dev

How do I pass a value to a method that calls a new page in the Controller class of the method?

From Dev

How do I pass arguments to my handler

From Dev

Laravel: how do I pass obj std class to my view and call it and the difference with passing a simple array?

From Dev

How do I pass two parameters as XML to my controller class on Java Scene Builder?

From Dev

How do I pass an ArrayList of Objects from my main method to a method in another class (to then be sorted by a specific property)

From Dev

How do I view my environment variables?

From Dev

How do I correctly define my variables?

From Java

How do I pass class names as arguments?

From Dev

How do I pass a class to a method in Nashorn?

From Dev

How do I pass a class as a parameter in Swift?

From Dev

How do I store class variables in memory?

From Dev

IntelliJ how do I generate a new class?

From Dev

How can I pass variables into my title with Latex Interpretation?

From Dev

How do I make my JFrame class my main class?

From Dev

How do I calculate a new column in Pandas based a on trignometric function?

Related Related

  1. 1

    How do I use toString to retrieve my information in my class and how do I get my method to calculate the "GPA" in this class?

  2. 2

    how do i transfer this form.cs code in my new class calculate?

  3. 3

    How do I pass variables into my class, ID, or data attribute in RiotJS?

  4. 4

    How do i pass my scope correctly to look for variables

  5. 5

    How to calculate a sum from my class variables?

  6. 6

    How do i pass the Label4.Text to a new class?

  7. 7

    How do I override `toString` in my derived class and use the private instance variables from the base class?

  8. 8

    How do I pass variables to a jQuery function?

  9. 9

    How do I pass variables around in Python?

  10. 10

    how do I pass variables to angularjs factories

  11. 11

    How do I pass environment variables to babelrc?

  12. 12

    How do I pass node.js server variables into my angular/html view?

  13. 13

    Trying to add a partial form to my index page. How do I pass multiple variables to generate the form?

  14. 14

    VB 13 windows form - how do I pass my variable between two forms [New to coding]

  15. 15

    How do I pass a value to a method that calls a new page in the Controller class of the method?

  16. 16

    How do I pass arguments to my handler

  17. 17

    Laravel: how do I pass obj std class to my view and call it and the difference with passing a simple array?

  18. 18

    How do I pass two parameters as XML to my controller class on Java Scene Builder?

  19. 19

    How do I pass an ArrayList of Objects from my main method to a method in another class (to then be sorted by a specific property)

  20. 20

    How do I view my environment variables?

  21. 21

    How do I correctly define my variables?

  22. 22

    How do I pass class names as arguments?

  23. 23

    How do I pass a class to a method in Nashorn?

  24. 24

    How do I pass a class as a parameter in Swift?

  25. 25

    How do I store class variables in memory?

  26. 26

    IntelliJ how do I generate a new class?

  27. 27

    How can I pass variables into my title with Latex Interpretation?

  28. 28

    How do I make my JFrame class my main class?

  29. 29

    How do I calculate a new column in Pandas based a on trignometric function?

HotTag

Archive