EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 8, Problem 7PE

a.

Explanation of Solution

Program:

File name: “CollegeCourse.java

//Define a class named CollegeCourse

public class CollegeCourse

{

    //Declare the private variables

    private String courseID;

    private int credits; 

    private char grade;

    //Define a get method that returns the course ID

    public String getID()

    {

        //Return the value

        return courseID;

    }

    //Define a get method that returns the credit hours

    public int getCredits()

    {

        //Return the value

        return credits;

    }

    //Define a get method that returns the letter grade

    public char getGrade()

    {

        //Return the value

        return grade;

    }

    //Define a set method that takes the course ID

    public void setID(String idNum)

    {

        //Assign the value

        courseID = idNum;

    }

    //Define a set method that takes the credit hours

    public void setCredits(int cr)

    {

        //Assign the value

        credits = cr;

    }

    //Define a set method that takes the letter grade

    public void setGrade(char gr)

    {

        //Assign the value

        grade = gr;

    }

}

File name: “Student...

b.

Explanation of Solution

Program:

File name: “InputGrades.java

//Import necessary header files

import college.CollegeCourse;

import college.Student;

import javax.swing.*;

//Define a class named InputGrades

public class InputGrades

{

    //Define a main method

    public static void main(String[] args)

    {

        //Declare an array to store data of 10 students

        Student[] students = new Student[10];

        //Declare the variables and initialize the values

        int x, y, z;

        String courseEntry, entry  = "",  message;

        int idEntry, credits;

        char gradeEntry = ' ';

        boolean isGoodGrade =  false;

        final int NUM_COURSES = 5;

        //Declare an array to store five grades

        char[] grades = {'A', 'B', 'C', 'D', 'F'};

        //For loop to be executed until x exceeds 10

        for(x = 0; x < students.length; ++x)

        {

            //Create a student object

            Student stu = new Student();

            //Prompt the user to enter the student ID

entry = JOptionPane.showInputDialog(null, "For student #" +

            (x + 1) + ", enter the student ID");

            idEntry  = Integer.parseInt(entry);

            //Function call

            stu.setID(idEntry);

            //For loop to be executed until y exceeds 5

            for(y = 0; y < NUM_COURSES; ++y)

            {

                //Prompt the user to enter the course

                courseEntry = JOptionPane.showInputDialog(null,

                "For student #" + (x + 1) + ", enter course #" +

                (y + 1));

//Prompt the user to enter the credits for each //course

                entry  = JOptionPane.showInputDialog(null,

                "For student #" + (x + 1) +

                ", enter credits for course  #" + (y + 1));

                credits = Integer.parseInt(entry);

                //Assign the value false to isGoodGrade

                isGoodGrade = false;

                //While the user does not enter isGoodGrade

                while(!isGoodGrade)

                {

//Prompt the user to enter the grade for //course

                    entry  = JOptionPane.showInputDialog(null,

                    "For student #" + (x + 1) +

                    ", enter grade for course  #" + (y + 1));

                    gradeEntry = entry...

Blurred answer
Students have asked these similar questions
Design a class named CustomerRecord that holds a customer number, name, and address. Include separate methods to 'set' the value for each data field using the parameter being passed. Include separate methods to 'get' the value for each data field, i.e. "return" the field's value. Pseudocode:
Create a BowlingTeam class The class has 2 fields: a field for the team name and an array that holds the team members’ names. Create get and set methods for the teamName field. Add a setMember method that sets a team member’s name. The method requires a position and a name, and it uses the position as a subscript to the members array. Add a getMember method that returns a team member’s name. The method requires a value used as a subscript that determines which member’s name to return. Create a BowlingTeamDemo class. In the main method include the following: Declare 2 variables: name and a constant NUM_TEAMS that holds 4 Bowling Team objects. Declare and instantiate an array teams of BowlingTeam objects. Using nested for loops, prompt the user to enter the 4 team names and enter the team members’ names. Using another nested for loop, output each team’s name and their team members’. Output should look like: Members of team The Lucky Strikes Carlos Diego Rose Lynn   Members of team I…
use this code template to help you continue: private boolean included Indicates whether the item should be taken or not   public Item(String name, double weight, int value) Initializes the Item’s fields to the values that are passed in; the included Field is initialized to false   public Item(Item other)  Initializes this item’s fields to the be the same as the other item’s   public void setIncluded(boolean included) Setter for the item’s included field (you don’t need setters for the other fields)   Given code: public class Item {       private final String name;     private final double weight;     private final int value;       public Item(String name, double weight, int value) {         this.name = name;         this.weight = weight;         this.value = value;     }       static int max(int a, int b)     {         if(a > b)             return a;         return b;     }       // function to print the items which are taken     static void printSelection(int W, Item[] items, int…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s;License: Standard YouTube License, CC-BY