Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So essentially I'm trying to find a way to get the StudentDemo class to print the values from the Student class more specifically from the

So essentially I'm trying to find a way to get the StudentDemo class to print the values from the Student class more specifically from the hasPassed method and the gradeCredits method, I've tried making a new class object for Student.class but goes to the constructor instead, any lines syntax will be very helpful.

An example for what I'm looking for:

Input:

Please enter your name: Marge Simpson

Please enter the number of credits you have earned: 46

Please enter your average grade: 86.92

Please enter the number of credits required for your major: 40

Output:

Hello Marge Simpson.

The letter grade corresponding to your average grade is B.

This grade is passing.

The number of grade credits you have earned is 4128.70.

Here's the code that I have so far.

/** * Student.java * */

//Put any imports below this line. import java.util.Scanner; /** * Short, one-line description of Student class here. * * Optionally, include a paragraph that provides a more

* detailed description. * * @author (author) * @version (10/22/2018) */ public class Student {

private String studentName; private int credits; private double averageGrade;

public Student(String name, int newCredits, double grades) { studentName = name; credits = newCredits; averageGrade = grades; }

public char letterGrade() { char letter = 'A'; if (averageGrade <= 100) { letter = 'A'; System.out.println("Your grade is " + letter); if(averageGrade < 90) { letter = 'B'; System.out.println("Your grade is " + letter); if (averageGrade < 80) { letter = 'C'; System.out.println("Your grade is " + letter); if (averageGrade < 70) { letter = 'D'; System.out.println("Your grade is " + letter); if (averageGrade < 60) { letter = 'F'; System.out.println("Your grade is " + letter); } } } } return letter; } else { System.out.println("Invalid number"); } return letter; }

public String hasPassed(char letter) { switch (letter) { case 'A': case 'B': case 'C': case 'D': { System.out.println("This grade is passing."); } break; default: { letter = 'F'; System.out.println("This grade is failing."); } break; } String str = Character.toString(letter); return str; }

public double gradeCredits(int credits) { Scanner input = new Scanner(System.in); System.out.println("Enter the amount of credits required: "); int creditsRequired = input.nextInt();

if (credits > creditsRequired) {

credits += (credits - creditsRequired) * 1.25;

} return credits; }

public String getStudentName() { return studentName; }

public void setStudentName(String name) { studentName = name; }

public int getCredits() { return credits; }

public void setCredits( int cred) { credits = cred; }

public double getAverageGrade() { return averageGrade; }

public void setAverageGrade(double grades) { averageGrade = grades; }

}

//below is the student demo class that contains the main method where the input is placed

import java.util.Scanner; /** * Write a description of class StudentDemo here. * * @author (your name) * @version (a version number or a date) */ public class StudentDemo { public StudentDemo() {

} public static void main(String[] args) { Scanner input = new Scanner(System.in); Student stu = new Student(); System.out.println("Student's Name: "); String studentName = input.nextLine(); System.out.println("Number of credits: "); int credits = input.nextInt(); System.out.println("Average Grade: "); double averageGrade = input.nextDouble(); System.out.println("credits needed: "); int creditsReq = input.nextInt(); System.out.println("Hello" + studentName + "."); System.out.println("The letter grade " + "corresponding of your average grade is" + stu.letterGrade()); System.out.println("This grade is " + stu.hasPassed()); System.out.println("The number of credits you have earned is " + stu.getCredits); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions

Question

List the goals of a persuasive message.

Answered: 1 week ago