Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having issues with a simple program that works correctly, but I have to submit it to Zybooks which runs several tests on it and

I'm having issues with a simple program that works correctly, but I have to submit it to Zybooks which runs several tests on it and gave me a 2/10. I posted a picture of what tests I passed and which failed and I pasted my program below. Any help will be much appreciated!

image text in transcribed

public class Planner { /* * The maximum number of students that may be enrolled in a single section. * Use this and the number of students enrolled in the class to calculate * then number of sections needed for the class. */ private static final int MAX_SECTION_SIZE = 20;

/* * This stores the data for the class in the following order: * info[0] = class name (capitalized) * info[1] = class location * info[2] = number of students * info[3] = number of sections needed */ private String[] info;

/** * Constructor for Planning class. The constructor takes in an input * string, breaks it up, and then stores the pieces into the class * variable info. It also does a minor calculation to fill in info[3]. * * The class name must be capitalized when it is stored. * The number of sections is equal to the ceiling of (NumStudents/MAX_CLASS_SIZE) * * @param input A String containing information about the class. The input * will always be String of 4 elements separated by commas of the form: * "ClassName,ClassLocation,NumStudents" */ public Planner(String input) { //TODO: split input (look at String.split()) and store necessary information in the info array. String[] in = input.split(","); int numStudents = Integer.parseInt(in[2]); int sections; if (numStudents % MAX_SECTION_SIZE == 0) { sections = numStudents / MAX_SECTION_SIZE; } else { sections = numStudents / (MAX_SECTION_SIZE + 1); } input = input + "," + Integer.toString(sections); info = input.split(","); } /** * Getter method for the info array. * @return information */ public String[] getInfo() { // TODO: return info array return info; } /** * This is the toString method. It overrides the default toString method * to print out the information in the desired format. * * @return The string representation of the Planning object. The string is of the * format: * "CLASS: (className), LOCATION: (classLocation), ENROLLED: (numberStudents), SECTIONS: (numberSections)" * Replace the parenthesized section with the stored values. e.g. * if the class name is "CS2334", the first part of the string is "CLASS: CS2334" * Make sure that all spaces and punctation are replicated exactly. */ @Override public String toString() { //TODO: construct and return correct string. return String.format("CLASS: " + info[0].toUpperCase() + ", LOCATION: " + info[1] + ", ENROLLED: " + info[2] + ", SECTIONS: " + info[3]); } }

1: TestStoreClassname Test that class name is stored and capitalized in info array first index. Test feedback Info array does not contain capitalized class name in first index 2: TestStoreClassLocation Test that class location is stored in info array second index. 3: TestStoreClassSize Test that class size is stored in info array third index. 4: TestStoreNumberSections 0/3 Test that number of sections is calculated correctly and stored in info array fourth index Info array does not contain correct number of sections in fourth index. Test feedback 5: TestPlannerTString 0/4 Tests the planner class toString Planner class tostring is incorrect. Make sure you replicate the format Test feedback

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

More Books

Students also viewed these Databases questions

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago

Question

3. Describe phases of minority identity development.

Answered: 1 week ago