Question

JAVA Only need help with (D) if you can explain to me where this method needs...

JAVA

Only need help with (D) if you can explain to me where this method needs to go? Should I place this method name ( SETNAME()) in the main method or in the gpa method ??

D) - Add one more method name it setName(), this method should read the name of student from input stream and return to main method.

Write a method to accept n integer number between 0 and 100 and return the average. B)-Write a method to convert an integer number between 0 and 100 to latter grade A to F and return. C)- Write a method to compute GPA for following letter grade and return the GPA value On Part III:     D) - Add one more method name it setName(), this method should read the name of student from input stream and return to main method.

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

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

\// NameScoreGrade.java

import java.util.Scanner;

public class NameScoreGrade {
   /*
   * Creating an Scanner class object which is used to get the inputs entered
   * by the user
   */
   static Scanner sc = new Scanner(System.in);

   public static void main(String[] args) {
       String name = setName();

       double avg = readscores();
      
       char letterGrade = findLetterGrade(avg);
       double gpa = computeGPA(letterGrade);

       System.out.println("Name :" + name);
       System.out.println("Average Score :" + avg);
       System.out.println("Letter Grade :" + letterGrade);
       System.out.println("GPA :" + gpa);
      
      
   }

   private static double computeGPA(char letterGrade) {
       double gpa = 0;
       if (letterGrade == 'A')
           gpa = 4;
       else if (letterGrade == 'B')
           gpa = 3;
       else if (letterGrade == 'C')
           gpa = 2;
       else if (letterGrade == 'D')
           gpa = 1;
       else if (letterGrade == 'F')
           gpa = 0;

       return gpa;
   }

   private static char findLetterGrade(double average) {
       char gradeLetter = 0;
       if (average >= 90 && average <= 100)
           gradeLetter = 'A';
       else if (average >= 80 && average < 90)
           gradeLetter = 'B';
       else if (average >= 70 && average < 80)
           gradeLetter = 'C';
       else if (average >= 60 && average < 70)
           gradeLetter = 'D';
       else if (average < 60)
           gradeLetter = 'F';
       return gradeLetter;
   }

   private static double readscores() {
       int n, score, sum = 0;
       System.out.print("How many scores you want to enter :");
       n = sc.nextInt();

       for (int i = 0; i < n; i++) {
           System.out.print("Enter Score#" + (i + 1) + ":");
           score = sc.nextInt();
           sum += score;
       }

       return ((double) sum) / n;
   }

   private static String setName() {
       String name = null;

       // Getting the input entered by the user
       System.out.print("Enter name :");
       name = sc.nextLine();
       return name;
   }

}

=============================

Output:

Enter name :Kane Williams
How many scores you want to enter :5
Enter Score#1:89
Enter Score#2:98
Enter Score#3:87
Enter Score#4:76
Enter Score#5:65
Name :Kane Williams
Average Score :83.0
Letter Grade :B
GPA :3.0

=====================Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
JAVA Only need help with (D) if you can explain to me where this method needs...
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
  • HINT 1)-Write a method to accept n integer number between 0 and 100 and return the...

    HINT 1)-Write a method to accept n integer number between 0 and 100 and return the average. 2)-Write a method to convert an the letter grade as follow. integer number between 0 and 100 to latter grade A to F and return. 100-90->A 89-80->B 79-70->C 69-60->D 00-59->F 3)-Write a method to compute GPA for following letter grade and return the GPA value. A =>4.0 B ->3.0 C->20 D->1.0 Hint for option 1 1 import java.util.Scanner 2 public class ProjPart2 3...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • PLEASE DO IN JAVA 3) Add the following method to College: 1. sort(): moves all students...

    PLEASE DO IN JAVA 3) Add the following method to College: 1. sort(): moves all students to the first positions of the array, and all faculties after that. As an example, let fn indicate faculty n and sn indicate student n. If the array contains s1|f1|f2|s2|s3|f3|s4, after invoking sort the array will contain s1|s2|s3|s4|f1|f2|f3 (this does not have to be done “in place”). Students and faculty are sorted by last name. You can use any number of auxiliary (private) methods, if needed....

  • in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a...

    in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a program that asks the user for an input file name, open, read ar number of students is not known. For each student there is a name and and display a letter grade for each student and the average test score fc • openFile: This method open and test the file, if file is not found and exit. Otherwise, return the opened file to the...

  • Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an...

    Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an integer. Once the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Do not use a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be...

  • Write a Java program that reads a file until the end of the file is encountered....

    Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...

  • You will create a class to store information about a student�s courses and calculate their GPA....

    You will create a class to store information about a student�s courses and calculate their GPA. Your GPA is based on the class credits and your grade. Each letter grade is assigned a point value: A = 4 points B = 3 points C = 2 points D = 1 point An A in a 3 unit class is equivalent to 12 grade points (4 for the A times 3 unit class) A C in a 4 unit class is...

  • Java - In NetBeans IDE: • Create a class called Student which stores: - the name...

    Java - In NetBeans IDE: • Create a class called Student which stores: - the name of the student - the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

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