Question

I'm still fairly new to java and I haven't programmed with it in half a year,...

I'm still fairly new to java and I haven't programmed with it in half a year, so I can't for the life of me figure this out even though I know its really simple. I'll paste the 2 classes below so any help is much appreciated. The TODO comments are what I'm supposed to do.

public class Main
{
public static void main(String[] args)
{
/*
* This is for the first part of the lab.
*/
  
Planner coursePlan = new Planner("cs2334,Dale Hall,100");
System.out.println(coursePlan);
}
}

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

/**
* Getter method for the info array.
* @return information
*/
public String[] getInfo()
{
// TODO: return info array
}

/**
* 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.
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

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 num=Integer.parseInt(in[2]);
int sec;
if(num%20==0)
sec=num/20;
else
sec=num/20+1;
input=input+","+Integer.toString(sec);
info=input.split(",");
}

/**
* Getter method for the info array.
* @return information
*/
public String[] getInfo()
{
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()
{
return String.format("Class: "+info[0].toUpperCase()+", LOCATION: "+info[1].toUpperCase()+", ENROLLED: "+info[2].toUpperCase()+", SECTIONS: "+info[3].toUpperCase());
//TODO: construct and return correct string.
}
}
public class Main
{
public static void main(String[] args)
{
/*
* This is for the first part of the lab.
*/
  
Planner coursePlan = new Planner("cs2334,Dale Hall,100");
System.out.println(coursePlan.toString());
}
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
I'm still fairly new to java and I haven't programmed with it in half a year,...
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
  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...

  • I have a java class that i need to rewrite in python. this is what i...

    I have a java class that i need to rewrite in python. this is what i have so far: class Publisher: __publisherName='' __publisherAddress=''    def __init__(self,publisherName,publisherAddress): self.__publisherName=publisherName self.__publisherAddress=publisherAddress    def getName(self): return self.__publisherName    def setName(self,publisherName): self.__publisherName=publisherName    def getAddress(self): return self.__publisherAddress    def setAddress(self,publisherAddress): self.__publisherAddress=publisherAddress    def toString(self): and here is the Java class that i need in python: public class Publisher { //Todo: Publisher has a name and an address. private String name; private String address; public Publisher(String...

  • In Java programming language Please write code for the 6 methods below: Assume that Student class...

    In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java...

    Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>();   // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString());       //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234");    // printing information System.out.println(part2.toString());    //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...

  • JAVA help Create a class Individual, which has: Instance variables for name and phone number of...

    JAVA help Create a class Individual, which has: Instance variables for name and phone number of individual. Add required constructors, accessor, mutator, toString() , and equals method. Use array to implement a simple phone book , by making an array of objects that stores the name and corresponding phone number. The program should allow searching in phone book for a record based on name, and displaying the record if the record is found. An appropriate message should be displayed if...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

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