r/programminghelp • • Feb 01 '21

Java What is a public void input?

Hello, I am currently working on a Java assignment, but I have never come across this phrase before, and my prof. won't get back to me. This is my assignment:

"

Write a class in Java named Student whose UML class diagram is shown below. The default (no-parameter) constructor should initialize the String data members to the empty String( “ “) and the double member to 0.0. The input method should allow users to input the values of the object’s data members using prompted console input. Do not use pop-up dialog boxes for this input! The toString( ) method is important for effective output. Note that in the diagram, private access is denoted with a minus sign ( - ) and public access is denoted with a plus sign ( + ).

Student class

- String name //Student Name

-String id //Student ID (s + 8 digits)

- double gpa //Student GPA (0.0 tp 4.0)

+Student() //Default constructor

+Student(String, String, double) //All parameters contructor

+String toString()

+void input() //Console input of Student object

+void set(String, String, double) //Sets all instance variables

+String getName()

+String getID()

+String getGPA()

"

My code so far:

import java.util.Scanner;

public class Student
{
    private String name;
    private String id;
    private double gpa;
    
    public Student(String n, String i, double g)
    {
        name = n;
        id = i;
        gpa = g;
    }
    
    public String toString()
    {
        return( name +
                "\ntheir student id is : "+ id + 
                "\nand their gpa is : "+ gpa);
    }
    
    public void input()
    {
        
        
    }
    
    public void set(String n, String i, double g)
    {
        name = n;
        id = i;
        gpa =g;
    }
    
    public String getName()
    {
        return name;
    }
    
    public String getID()
    {
        return id;
    }
    
    public double getGPA()
    {
        return gpa;
    }
}

Any help as to what it is that I'm supposed to do with the public void input() would be absolutely appreciated.

3 Upvotes

4 comments sorted by

3

u/amoliski Feb 01 '21

The input method should allow users to input the values of the object’s data members using prompted console input.

This part goes in input() - basically ask the name, id, and GPA, parse out the responses, and update your object.

2

u/ijayare Feb 01 '21 edited Feb 01 '21

What do you mean by ask the name, id, and gpa? Do you mean, like, fruit = banana for example? I’ll admit, I don’t understand pseudo-code very well yet, so I often times feel lost without examples.

1

u/amoliski Feb 01 '21

As in have the program print out "what is the student's name", and then run a function that reads the user's response from the console input.

https://www.programiz.com/java-programming/basic-input-output

2

u/ijayare Feb 01 '21

Ah, thank you for that! That helped.