Question

import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

import java.util.Scanner;

public class StudentClient {

  

   public static void main(String[] args)
   {
       Student s1 = new Student();
        Student s2 = new Student("Smith", "123-45-6789", 3.2);
        Student s3 = new Student("Jones", "987-65-4321", 3.7);
        System.out.println("The name of student #1 is ");
        System.out.println("The social security number of student #1 is " + s1.toString());
        System.out.println("Student #2 is " + s2);
        System.out.println("the name of student #3 is " + s3.getName());
        System.out.println("The social security number of student is " + s3.getSsn());
        System.out.println("The gpa of student #3 is " + s3.getGpa());
        System.out.println("Student #3 is " + s3.toString());
      
        s3.setName("Adam");
        s3.setSsn("555-55-5555");
        s3.setGpa(4.0);
        System.out.println("Here is student #3 after the changes: " + s3.toString());
        System.out.println("Now set the gpa of student #2 to 5.0 " );
        s2.setGpa(5.0);
        System.out.println("\n" + "student #2 is " + s2.toString());
        System.out.println("There are students ");
      
      
   }

import java.util.Scanner;
public class Student
{
   
        private String name;
        private String ssn;
        private double gpa;
        private static int studentCount = 0;
        public Student()
        {
        name = "";
        ssn = "";
        gpa = 0.0;
        studentCount++;
        }
       
        public Student(String newName, String newSsn, double newGpa)
        {
            name = newName;
            ssn = newSsn;
            gpa = newGpa;
            studentCount++;
        }
       
        public String getName()
        {
            return name;
        }
       
        public void setName(String newName)
        {
           
            name = newName;
           
        }
       
        public String getSsn()
        {
            return ssn;
        }
       
        public void setSsn(String newSsn)
        {
            ssn = newSsn;
        }
       
        public double getGpa()
        {
            return gpa;
        }
       
        public void setGpa(double newGpa)
        {
           
            if(newGpa > 0.0 && newGpa <= 4.0)
            gpa = newGpa;
            else
            {
                System.err.println("GPA must be betweeb 0.0 and 4.0. Value not changed.");   
            }
        }
       
       
        public static int getCount()
        {
            return getCount();
        }
       
        public String toString()
        {
            return("Name: " + name + " SSN: " + ssn + " GPA: " + gpa);
        }
       
       

Use a getcount() method to get the number of students ?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

I have modified the code and highlighted the code changes below.

StudentClient.java


import java.util.Scanner;
public class StudentClient {
  
public static void main(String[] args)
{
Student s1 = new Student();
Student s2 = new Student("Smith", "123-45-6789", 3.2);
Student s3 = new Student("Jones", "987-65-4321", 3.7);
System.out.println("The name of student #1 is ");
System.out.println("The social security number of student #1 is " + s1.toString());
System.out.println("Student #2 is " + s2);
System.out.println("the name of student #3 is " + s3.getName());
System.out.println("The social security number of student is " + s3.getSsn());
System.out.println("The gpa of student #3 is " + s3.getGpa());
System.out.println("Student #3 is " + s3.toString());
  
s3.setName("Adam");
s3.setSsn("555-55-5555");
s3.setGpa(4.0);
System.out.println("Here is student #3 after the changes: " + s3.toString());
System.out.println("Now set the gpa of student #2 to 5.0 " );
s2.setGpa(5.0);
System.out.println("\n" + "student #2 is " + s2.toString());
System.out.println("There are students ");
System.out.println("Number of studnets: "+Student.getCount());
  
}
}

Student.java


import java.util.Scanner;
public class Student
{

private String name;
private String ssn;
private double gpa;
private static int studentCount = 0;
public Student()
{
name = "";
ssn = "";
gpa = 0.0;
studentCount++;
}

public Student(String newName, String newSsn, double newGpa)
{
name = newName;
ssn = newSsn;
gpa = newGpa;
studentCount++;
}

public String getName()
{
return name;
}

public void setName(String newName)
{

name = newName;

}

public String getSsn()
{
return ssn;
}

public void setSsn(String newSsn)
{
ssn = newSsn;
}

public double getGpa()
{
return gpa;
}

public void setGpa(double newGpa)
{

if(newGpa > 0.0 && newGpa <= 4.0)
gpa = newGpa;
else
{
System.err.println("GPA must be betweeb 0.0 and 4.0. Value not changed.");   
}
}


public static int getCount()
{
return studentCount;
}

public String toString()
{
return("Name: " + name + " SSN: " + ssn + " GPA: " + gpa);
}

}

Output:

The name of student #1 is
The social security number of student #1 is Name: SSN: GPA: 0.0
Student #2 is Name: Smith SSN: 123-45-6789 GPA: 3.2
the name of student #3 is Jones
The social security number of student is 987-65-4321
The gpa of student #3 is 3.7
Student #3 is Name: Jones SSN: 987-65-4321 GPA: 3.7
Here is student #3 after the changes: Name: Adam SSN: 555-55-5555 GPA: 4.0
Now set the gpa of student #2 to 5.0

student #2 is Name: Smith SSN: 123-45-6789 GPA: 3.2
There are students
Number of studnets: 3
GPA must be betweeb 0.0 and 4.0. Value not changed.

Add a comment
Know the answer?
Add Answer to:
import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • // Client application class and service class Create a NetBeans project named StudentClient following the instructions...

    // Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...

  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{       ...

    Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{        File prg8 = new File("program8.txt");        Scanner reader = new Scanner(prg8);        String cName = "";        int cID = 0;        double bill = 0.0;        String email = "";        double nExempt = 0.0;        String tExempt = "";        int x = 0;        int j = 1;        while(reader.hasNextInt()) {            x = reader.nextInt();}        Customers c1 [] = new Customers [x];        for (int...

  • import java.util.Scanner; public class MPGMain {    public static void main(String[] args)    {       ...

    import java.util.Scanner; public class MPGMain {    public static void main(String[] args)    {        Scanner input = new Scanner(System.in);               Mileage mileage = new Mileage();               System.out.println("Enter your miles: ");        mileage.setMiles(input.nextDouble());               System.out.println("Enter your gallons: ");        mileage.setGallons(input.nextDouble());               System.out.printf("MPG : %.2f",mileage.getMPG());           } } public class Mileage {    private double miles;    private double gallons;    public double getMiles()...

  • How to solve this problem? Consider the following class : public class Store Public final double...

    How to solve this problem? Consider the following class : public class Store Public final double SALES TAX_RATE = 0.063B private String name; public Store(String newName) setName ( newName); public String getName () { return name; public void setName (String newName) { name = newName; public String toString() return "name: “ + name; Write a class encapsulating a web store, which inherits from Store. A web store has the following additional attributes: an Internet Address and the programming language in...

  • Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args)...

    Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

  • import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y,...

    import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...

  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 {    public static void main(String[] args)    {...

    import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 {    public static void main(String[] args)    {        String name;        String answer;        int correct = 0;        int incorrect = 0;        Scanner phantom = new Scanner(System.in);        System.out.println("Hello, What is your name?");        name = phantom.nextLine();        System.out.println("Welcome " + name + "!\n");        System.out.println("My name is Danielle Brandt. "            +"This is a quiz program that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT