×
Reviews 4.9/5 Order Now

Create a Program to Implement Object Oriented Programming in Java Assignment Solution

June 22, 2024
Jessica Miller
Jessica Miller
🇺🇸 United States
Java
Jessica Miller is a seasoned programmer with a master's degree in software engineering from Stanford University. Having completed over 700 Java assignments, Jessica excels in implementing sorting algorithms, multi-dimensional arrays, and efficient array operations. Her deep understanding of complex programming concepts and hands-on experience make her a valuable resource for students seeking high-quality homework help.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Focus on Rust’s strict ownership rules and borrow checker to avoid common errors. Use tools like clippy for linting and cargo for dependency management to ensure clean and efficient code.
News
The rise of languages such as Rust and Go is notable for their performance and safety features, making them increasingly popular in systems programming.

Instructions

Objective

Write a java assignment program to implement object oriented programming.

Requirements and Specifications

program-to-implement-object-oriented-programming-in-java

Source Code

import java.io.File; import java.util.Scanner; public class DataStore { private static DataStore instance; private final String SECTIONS_FILENAME = "sections1.txt"; private Section[] sections; private int numSections; // Load the sections from file private DataStore() { sections = new Section[10]; numSections = 0; try { Scanner inFile = new Scanner(new File(SECTIONS_FILENAME)); while (inFile.hasNext()) { String subject = inFile.next(); String number = inFile.next(); String name = inFile.next(); String id = inFile.next(); String days = inFile.next(); String startTime = inFile.next(); String building = inFile.next(); String room = inFile.next(); Section section = new Section(subject, number, name, id, days, startTime, building, room); addSection(section); } inFile.close(); } catch (Exception e) { e.printStackTrace(System.out); System.exit(0); } } // Return a list of sections public Section[] getSections() { Section[] result = new Section[numSections]; for (int i = 0; i < numSections; i++) { result[i] = sections[i]; } return result; } // Add a new section to the data store public void addSection(Section section) { if (numSections >= sections.length) { sections = expandSections(sections); } sections[numSections++] = section; } // Expand the objects twice its size, made it an 'object' instead // of a specific data type to make it more generic and applicable // to other arrays as well if in case we expand this program private Section[] expandSections(Section[] objects) { Section[] newSections = new Section[objects.length * 2]; for (int i = 0; i < objects.length; i++) { newSections[i] = objects[i]; } return newSections; } // Return the only instance of a data store public static DataStore getInstance() { if (instance == null) { instance = new DataStore(); } return instance; } }

Similar Samples

At ProgrammingHomeworkHelp.com, explore our curated samples of programming assignments across various languages and difficulty levels. These examples demonstrate our expertise in delivering precise, well-commented solutions. Whether you're grappling with Java, Python, or C++, our samples showcase how we ensure clarity and quality in every task. Discover how we can elevate your programming skills today.