Question

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 [ ]

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

*****NOTE: IF YOU WANT CODE FOR CollegeDegree please comment below ...

CODE TO COPY

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);

   }

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

EXPLANATION

import java.util.Scanner;

public class CollegeDegreeDemo {

   public static void main(String[] args) {

// Create an object of the Scanner class that takes input from System.in and refer to this object as keyboard
       Scanner keyboard = new Scanner(System.in);

// Create an object of the CollegeDegree class and refer to this object as myDegree
       CollegeDegree myDegree = new CollegeDegree();

// Create a variable of the int data type called option

       int option;

// Open a do/while loop

       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 : ");

// Save the user’s input into the option variable
           option = keyboard.nextInt();

// 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
           if (option == 1) {
               System.out.println("Enter new Major Name:");
               keyboard.nextLine(); // TO AVOID SKIIPING OF USER INPUT ..MUST BE USED AFTER NEXTINT
               String major = keyboard.nextLine();
               myDegree.setMajor(major);
           }

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

else if (option == 2) {
               myDegree.getMajor();
           }

// else if the user picks option 3,

else if (option == 3) {

//prompt the user for the name of the course and save this input into variable called courseName
               System.out.println("Enter course name:");
               keyboard.nextLine(); // TO AVOID SKIIPING OF USER INPUT ..MUST BE USED AFTER NEXTINT

//prompt the user for the number of credits and save this input into a variable called numberOfCredits
               String courseName = keyboard.nextLine();
               System.out.println("Enter number of courses");
               int numberOfCredits = keyboard.nextInt();
               keyboard.nextLine(); // TO AVOID SKIIPING OF USER INPUT ..MUST BE USED AFTER NEXTINT

//add this course to myDegree
               myDegree.addCourse(courseName, numberOfCredits);
           }

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

else if (option == 4) {
               System.out.println(myDegree.getCourses());
           }

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

else if (option == 5) {
               System.out.println("Number of courses:" + myDegree.getNumberOfCourses());
           }

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

else if (option == 6) {
               System.out.println("Total number of credits:" + myDegree.getTotalNumberOfCredits());
           }

// else if the user picks option 7,

else if (option == 7) {

//prompt the user for the new maximum number of courses and save this input into a variable called newMaximumNumberOfCourses
               System.out.println("Enter new Maximum NUmber of courses");
               int newMaximumNumberOfCourses = keyboard.nextInt();
               keyboard.nextLine(); // TO AVOID SKIIPING OF USER INPUT ..MUST BE USED AFTER NEXTINT

//increase the number of maximum courses for all college degrees
               myDegree.increaseMaximumNumberOfCourses(newMaximumNumberOfCourses);
           }

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

else if (option == 8) {
               System.out.println("Maximum number of courses: " + myDegree.getMaximumNumberOfCourses());
           }

// else if the user picks option 9, display Goodbye.

else if (option == 9) {
               System.out.println("Goodbye");
               break;//break the loop only when user enters 9
           }

//

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

else {
               System.out.println("Error...Please enter a valid option");
           }
       } while (option != 9);//close the do/while loop and make it so that it continues to run as long as the user does not pick option 9

   }

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

2 4 CollegeDegree.java CollegeDegree Demo.java X 1 import java.util.Scanner; 3 public class collegeDegreeDemo { 50 public sta14 20 21 24 26 28 29 30 31 33 34 35 38 CollegeDegree.java CollegeDegree Demo.java X sysLCI.UUL. PILIILII rico LU VIEW LIIC LU

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

NOTE:IF YOU WANT THE CODE FOR CollegeDegree   PLEASE COMMENT BELOW I WILL HELP YOU**

IF YOU HAVE ANY PROBLEM REGARDING THE SOLUTION PLEASE COMMENT BELOW I WILL HELP YOU

> can you provide code for CollegeDegree?

lib8 Tue, Apr 6, 2021 4:18 PM

Add a comment
Know the answer?
Add Answer to:
You may not add any instance variables to any class, though you may create local variables...
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...

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

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

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

  • 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 3 Develop the following class: Class Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables...

    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: QueueNode<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 type: T (parameterized type) Task: makes...

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

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

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