Question

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 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 nexMaximumNumberOfCourses 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 class CollegeDegreeDemo {

public static void 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
import java.util.Scanner;
 
public class CollegeDegreeDemo {
    
   public static void main(String[] args) {
      Scanner keyboard = new Scanner(System.in);
      CollegeDegree myDegree = new CollegeDegree();
       
      int option;
       
      do {
         System.out.println("Press 1 to change the major of the degree");
         System.out.println("Press 2 to view the major of the degree");
         System.out.println("Press 3 to add a course to the degree");
         System.out.println("Press 4 to view all the courses required for the degree");
         System.out.println("Press 5 to view the number of courses required for the degree");
         System.out.println("Press 6 to view the total number of credits required for the degree");
         System.out.println("Press 7 to increase the maximum number of courses for all degrees");
         System.out.println("Press 8 to view the maximum number of courses for all degrees");
         System.out.println("Press 9 to the end the program");
         System.out.println("Pick an option : ");
         option = keyboard.nextInt();
         if (option == 1) {
            System.out.println("Enter new Major Name:");
            keyboard.nextLine();
            String major = keyboard.nextLine();
            myDegree.setMajor(major);
         else if (option == 2) {
            myDegree.getMajor();
         else if (option == 3) {
            System.out.println("Enter course name:");
            keyboard.nextLine();
            String courseName = keyboard.nextLine();
            System.out.println("Enter number of courses");
            int numberOfCredits = keyboard.nextInt();
            keyboard.nextLine();
            myDegree.addCourse(courseName, numberOfCredits);
         else if (option == 4) {
            System.out.println(myDegree.getCourses());
         else if (option == 5) {
            System.out.println("Number of courses:" + myDegree.getNumberOfCourses());
         else if (option == 6) {
            System.out.println("Total number of credits:" + myDegree.getTotalNumberOfCredits());
         else if (option == 7) {
            System.out.println("Enter new Maximum NUmber of courses");
            int newMaximumNumberOfCourses = keyboard.nextInt();
            keyboard.nextLine();
            myDegree.increaseMaximumNumberOfCourses(newMaximumNumberOfCourses);
         else if (option == 8) {
            System.out.println("Maximum number of courses: " + myDegree.getMaximumNumberOfCourses());
         else if (option == 9) {
            System.out.println("Goodbye");
            break;
         else {
            System.out.println("Error...Please enter a valid option");
         }
      while (option != 9);
       
   }
    
}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
java
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
  • Step 1Develop the following class:ClassName: CollegeDegreeAccess Modifier: publicInstance variablesName: major...

    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 (default constructor)Task: sets major to the empty stringSets numberOfCourses to 0Sets courseNameArray to refer to an array of Strings with the number of elements equal to the value of the static variable maximumNumberOfCoursesSets courseCreditArray to...

  • 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 [...

  • 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 wp the professor. Please make sure to only implement what is...

    use intellij idea main java wp the professor. Please make sure to only implement what is asked for. 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 interface: Interface Name: Queue Interface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue...

  • 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:...

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

    use intellij idea main java Step 3 Develop the following class: Class Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables Name: front Access modifier: private Data type: Queue Node<T> Constructors: Name: ImprovedQueue Access modifier: public Parameters: none (default constructor) Task: sets the value of front to null Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Task: returns true if the front is equal to null; otherwise return false Name: dequeue Access modifier: public Parameters: none Return...

  • 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