×
Samples Blogs Make Payment About Us 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
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

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.