Question

Step 1Develop the following class:ClassName: CollegeDegreeAccess Modifier: publicInstance variablesName: major...

Step 1

Develop the following class:

Class

Name: CollegeDegree

Access Modifier: public

Instance variables

Name: major

Access modifier: private

Data type: String

Name: numberOfCourses

Access modifier: private

Data type: int

Name: courseNameArray

Access modifier: private

Data type: String [ ]

Name: courseCreditArray

Access modifier: private

Data type: int [ ]

Static variables

Name: maximumNumberOfCourses

Access modifier: private

Data type: int

Initial Value: 40

Constructor

Name: CollegeDegree

Access modifier: public

Parameters: none (default constructor)

Task: sets major to the empty string

Sets numberOfCourses to 0

Sets courseNameArray to refer to an array of Strings with the number of elements equal to the value of the static variable maximumNumberOfCourses

Sets courseCreditArray to refer to an array of ints with the number of elements equal to the value of the static variable maximumNumberOfCourses  

Non-static Methods

Name: setMajor

Access modifier: public

Parameters: newMajor

Return type: void

Task: sets the value of the instance variable major to the value of newMajor

Name: getMajor

Access modifier: public

Parameters: none

Return type: String

Task: returns the value of the instance variable major

Name: addCourse

Access modifier: public

Parameters: courseName (data type String), numberOfCredits (data type int)

Return type: void

Task: if numberOfCredits is greater than or equal to 1 and less than or equal to 5 and numberOfCourses is less than the length of the courseNameArray then place the value of courseName into the courseNameArray in the element whose index is equal to the instance variable numberOfCourses and place the value of numberOfCredits into the courseCreditArray in the element whose index is equal to the instance variable numberOfCourses and then increase the value of the instance variable numberOfCourses by 1

Name: getCourses

Access modifier: public

Parameters: none

Return type: String

Task: returns the concatenation of the name of each course located in the courseNameArray (Note: This can be accomplished by looping through the part of the courseNameArray that is filled with course names and concatenating each of these values into a single string)

Name: getNumberOfCourses

Access modifier: public

Parameters: none

Return type: int

Task: returns the value of the instance variable numberOfCourses

Name: getTotalNumberOfCredits

Access modifier: public

Parameters: none

Return type: int

Task: returns sum of the all the credits in the courseCreditArray (Note: This can be accomplished by looping through the part of the courseCreditArray that is filled with course credits and summing these into a single int)

Static Methods

Name: increaseMaximumNumberOfCourses

Access modifier: public

Parameters: nexMaximumNumberOfCourses

Return type: void

Task: if the value of is greater than the value of the static variable maximumNumberOfCourses then change the value of maximumNumberOfCourses to the value of newMaximumNumberOfCourses

Name: getMaximumNumberOfCourses

Access modifier: public

Parameters: none

Return type: int

Task: returns the value of the static variable maximumNumberOfCourses

Step 2

Develop a class with only a main method in it:

import java.util.Scanner;

public classCollegeDegreeDemo {

public staticvoid main(String[] args) {

/*   Inside of this main method do the following:

Create an object of the Scanner class that takes input from System.in and refer to this object as keyboard

Create an object of the CollegeDegree class and refer to this object as myDegree

Create a variable of the int data type called option


     Open a do/while loop

     Prompt the user to pick one of the following options:

     Press 1 to change the major of the degree

     Press 2 to view the major of the degree

     Press 3 to add a course to the degree

     Press 4 to view all the courses required for the degree

     Press 5 to view the number of courses required for the degree

     Press 6 to view the total number of credits required for the degree

     Press 7 to increase the maximum number of courses for all degrees

     Press 8 to view the maximum number of courses for all degrees

     Press 9 to the end the program

    

Save the user’s input into the option variable

if the user picks option 1, prompt the user for the major of the degree and save their input into a variable called newMajor and change the major of myDegree to the newMajor


else if the user picks option 2, display the major of myDegree


else if the user picks option 3, prompt the user for the name of the course and save this input into variable called courseName and prompt the user for the number of credits and save this input into a variable called numberOfCredits and add this course to myDegree

else if the user picks option 4, display the names of all the courses that are required for myDegree


else if the user picks option 5, display the number of courses that are required for myDegree

    

else if the user picks option 6, display the total number of credits that are required for myDegree


else if the user picks option 7, prompt the user for the new maximum number of courses and save this input into a variable called newMaximumNumberOfCourses and increase the number of maximum courses for all college degrees


else if the user picks option 8, display maximum number of courses for all degrees

else if the user picks option 9, display Goodbye.


else if the user picks any other option, display Error!


close the do/while loop and make it so that it continues to run as long as the user does not pick option 9

*/

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class CollegeDegree {
    private String major;
    private int numberOfCourses;
    private String[] courseNameArray;
    private int[] courseCreditArray;
    private static int maximumNumberOfCourses = 40;

    public CollegeDegree() {
        this.major = "";
        this.numberOfCourses = 0;
        this.courseNameArray = new String[maximumNumberOfCourses];
        this.courseCreditArray = new int[maximumNumberOfCourses];
    }

    public void setMajor(String major) {
        this.major = major;
    }

    public String getMajor() {
        return major;
    }

    public void addCourse(String courseName, int numberOfCredits) {
        if(numberOfCourses >= 1 && numberOfCourses <= 5 && numberOfCourses < courseNameArray.length) {
            courseNameArray[numberOfCourses] = courseName;
            courseCreditArray[numberOfCourses] = numberOfCredits;
            numberOfCourses++;
        }
    }

    public String getCourses() {
        String courses = "";
        for (int i = 0; i < numberOfCourses; i++) {
            courses += courseNameArray[i];
            if (i < numberOfCourses - 1) courses += " ";
        }
        return courses;
    }

    public int getNumberOfCourses() {
        return numberOfCourses;
    }

    public int geTotalNumberOfCredits() {
        int credits = 0;
        for (int i = 0; i < numberOfCourses; i++) {
            credits += courseCreditArray[i];
        }
        return credits;
    }

    public static void increaseMaximumNumberOfCourses(int nexMaximumNumberOfCourses) {
        if (nexMaximumNumberOfCourses > maximumNumberOfCourses) maximumNumberOfCourses = nexMaximumNumberOfCourses;
    }

    public static int getMaximumNumberOfCourses() {
        return maximumNumberOfCourses;
    }
}
Add a comment
Answer #2
[REMOVED]
Add a comment
Know the answer?
Add Answer to:
Step 1Develop the following class:ClassName: CollegeDegreeAccess Modifier: publicInstance variablesName: major...
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
  • You may not add any instance variables to any class, though you may create local variables...

    You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here.    Step 1 Develop the following class: Class Name: CollegeDegree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String [ ] Name: courseCreditArray Access...

  • You may not add any instance variables to any class, though you may create local variables...

    You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here. (I need step 2 please.) Step 1 Develop the following class: Class Name: CollegeDegree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String [...

  • java

    You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here.   Step 1Develop the following class:ClassName: CollegeDegreeAccess Modifier: publicInstance variablesName: majorAccess modifier: privateData type: StringName: numberOfCoursesAccess modifier: privateData type: intName: courseNameArrayAccess modifier: privateData type: String [ ]Name: courseCreditArrayAccess modifier: privateData type: int [ ]Static variablesName: maximumNumberOfCoursesAccess modifier: privateData type: intInitial Value: 40ConstructorName: CollegeDegreeAccess modifier: publicParameters: none...

  • Programming assignment for Java: Do not add any other instance variables to any class, but you...

    Programming assignment for Java: Do not add any other instance variables to any class, but you can create local variables in a method to accomplish tasks. Do not create any methods other than the ones listed below. Step 1 Develop the following class: Class Name: College Degree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String Name: courseCreditArray Access modifier:...

  • Step 1 Develop the following class: Class Name: CollegeDegree Access Modifier: public Instance variables Name: major...

    Step 1 Develop the following class: Class Name: CollegeDegree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String [ ] Name: courseCreditArray Access modifier: private Data type: int [ ] Static variables Name: maximumNumberOfCourses Access modifier: private Data type: int Initial Value: 40 Constructor Name: CollegeDegree Access modifier: public Parameters: none (default constructor) Task: sets major to the empty string...

  • Step 1 Develop the following class: Class Name: Bag Access Modifier: public Instance variables Name: name...

    Step 1 Develop the following class: Class Name: Bag Access Modifier: public Instance variables Name: name Access modifier: private Data Type: String Name: currentWeight Access modifier: private Data Type: double Name: maximumWeight Access modifier: private Data Type: double Constructors Name: Bag Access modifier: public Parameters: none (default constructor) Task: sets the value of the instance variable name to the empty string sets the value of the instance variable currentWeight to 0.0 sets the value of the instance variable maximumWeight to...

  • use intellij idea main java Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier:...

    use intellij idea main java Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data type: Queue Node<T> Constructors: Name: QueueNode Access modifier: public Parameters: info (data type T Task: sets the value of this.info to the value of the info parameter sets the value of link to null Methods Name: link Access modifier: private Data type: QueueNode<T> Constructors: Name:...

  • Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info...

    Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data type: QueueNode<T> Constructors: Name: QueueNode Access modifier: public Parameters: info (data type T) Task: sets the value of this.info to the value of the info parameter sets the value of link to null Methods Name: setInfo Access modifier: public Parameters: info (data type T) Return type: void Task: sets the...

  • Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access...

    Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data...

  • Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access...

    Step 1 Develop the following interface: Interface Name: QueueInterface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue Access modifier: public Parameters: none Return type: T (parameterized type) Name: enqueue Access modifier: public Parameters: element (data type T, parameterized type) Return type: void Step 2 Develop the following class: Class Name: QueueNode<T> Access Modifier: public Instance variables Name: info Access modifier: private Data type: T (parameterized type) Name: link Access modifier: private Data...

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