1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Veseljchak [2.6K]
2 years ago
8

It is common for people to name directories as dir1, dir2, and so on. When there are ten or more directories, the operating syst

em displays them in dictionary order, as dir1, dir10, dir11, dir12, dir2, dir3, and so on. That is irritating, and it is easy to fix. Provide a comparator that compares strings that end in digit sequences in a way that makes sense to a human. First compare the part before the digit as strings, and then compare the numeric values of the digits.
Your program should work with the provided test program
DirectorySortDemo.java.
Call the class you write DirectoryComparator.java.
Submit the two files in your submission.
DirectoryComparator.java
DirectorySortDemo.java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.collections;
public class DirectorySortDemo
{
public static void main (String [] args)
{
String dirNames ("dir12", "dir5", "dir9", "dirl", "dir4",
"lab10", "1ab2", "lab7", "lab17", "lab8",
"quiz8", "quiz10", "quiz11", "quiz12",
"dirll", "dir8", "dir7", "dir15", "dir3");
ArrayList directories = new
ArrayList<> (Arrays.asList (dirNames));
System.out.println ("Unsorted List:");
System.out.println (directories);
Collections.sort (directories, new DirectoryComparator ());
System.out.println ():
System.out-println ("Sorted List: ");
System.out.-println (directories);
Computers and Technology
1 answer:
Vikki [24]2 years ago
7 0

Answer:

Here the code is given as follows,

Explanation:

You might be interested in
Jasmine is a commercial artist her is is the one most often used by graphic designers publishers and others in her field the os
VikaD [51]
OS is for mac so she used the mac computer
7 0
2 years ago
"Write one statement that declares an integer variable numHouses initialized to 25."
katrin [286]

Answer:

int numHouses = 25;

Explanation:

The answer above is the Java and C++ prgramming languages' method of declaring and assinging a value to a variable.

To declare a variable, the variable type is written first , this could be (int for Integer, char for characters, double for decimal numbers, etc.), then followed by the name the programmer chooses to give to the variable which must not be a keyword or reserved word. The equality opereator performs the assignment operation of  assigning a value to the variable in this case 25.

int numHouses = 25;

int  is the variable type

numHouses  is the variable name

= is the assignment operator

25 is the assigned value

7 0
3 years ago
_____ specifies the format of a mail message and describes how mail is to be administered on the e-mail server and transmitted o
Hitman42 [59]

Answer:

SMTP (Simple Mail Transfer Protocol) specifies the format of a mail message and describes how mail is to be administered on the e-mail server and transmitted on the Internet

Explanation:

SMTP (Simple Mail Transfer Protocol)  is the protocol for the e-mail transmission over the internet.

The e-mails we send is forwarded over the SMTP, directed to the email servers.

SMTP does its job by breaking the email message into several categories so that the receiving server can understand how to deal with the e-mail message.

6 0
3 years ago
This performs Arithmetic and Logical Operations *
Zepler [3.9K]

Answer:

The ALU, it's pretty obvious lol!

3 0
2 years ago
Date Class Constructor – assigns fields to appropriate formal parameter – using the setters so error checking will occur. The co
lara31 [8.8K]

Answer:

Check the explanation

Explanation:

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

#include "Date.h"

#include "Person.h"

using namespace std;

const int MAXSIZE = 50;

// Prototypes go here

int loadArray(string fileName, Person students[]);

void sortByName(Person students[], int numE);

void printStudentReport(Person students[], int numE);

int main()

{

Person students[MAXSIZE];

int numE;

string fileName;

cout << "Enter the file name: ";

cin >> fileName;

numE = loadArray(fileName, students);

cout << endl;

cout << "Before Sort: " << endl;

printStudentReport(students, numE);

sortByName(students, numE);

cout << endl;

cout << "After Sort: " << endl;

printStudentReport(students, numE);

return 0;

}

int loadArray(string fileName, Person students[]){

ifstream in;

in.open(fileName.c_str());

if(in.fail())

return -1;

int n=0;

string fname, lname;

int month, day, year;

while(!in.eof()){

in>>fname>>lname>>month>>day>>year;

students[n] = Person(fname, lname, Date(month, day, year));

n++;

}

return n;

}

void sortByName(Person students[], int numE){

for(int i=0; i<numE; i++){

for(int j=i+1; j<numE; j++){

if(students[i].getLastName()>students[j].getLastName()){

Person temp = students[i];

students[i] = students[j];

students[j] = temp;

}

}

}

}

void printStudentReport(Person students[], int numE){

for(int i=0; i<numE; i++){

cout<<students[i].getLastName()<<", "<<students[i].getFirstName()<<"\t\t"<<students[i].getDateofBirth().toString()<<endl;

}

}

Person.h

#include<iostream>

#include<string>

using namespace std;

#include "Date.h"

#ifndef PERSON_H

#define PERSON_H

class Person{

private:

string firstName;

string lastName;

public:

Date dateOfBirth;

Person();

Person(string firstName, string lastName, Date dob);

string getFirstName();

string getLastName();

Date getDateofBirth();

void setFirstName(string fname);

void setLastName(string lname);

void setDateOfBirth(Date dob);

void setDateOfBirth(int month, int day, int year);

};

#endif

Person.cpp

#include "Person.h"

Person::Person(){

firstName = "";

lastName = "";

}

Person::Person(string firstName, string lastName, Date dob){

this->firstName = firstName;

this->lastName = lastName;

setDateOfBirth(dob.getMonth(), dob.getDay(), dob.getYear());

}

string Person::getFirstName(){

return firstName;

}

string Person::getLastName(){

return lastName;

}

Date Person::getDateofBirth(){

return dateOfBirth;

}

void Person::setFirstName(string fname){

firstName = fname;

}

void Person::setLastName(string lname){

lastName = lname;

}

void Person::setDateOfBirth(Date dob){

setDateOfBirth(dob.getMonth(), dob.getDay(), dob.getYear());

}

void Person::setDateOfBirth(int month, int day, int year){

dateOfBirth.setMonth(month);

dateOfBirth.setDay(day);

dateOfBirth.setYear(year);

}

Date.h

#include<iostream>

#include<string>

using namespace std;

#ifndef DATE_H

#define DATE_H

class Date{

private:

int day;

int month;

int year;

public:

Date();

Date(int month, int day, int year);

int getMonth();

int getDay();

int getYear();

void setMonth(int month);

void setDay(int day);

void setYear(int year);

string toString();

};

#endif

Date.cpp

#include "Date.h"

Date::Date(){

month = 1;

day = 1;

year = 1900;

}

Date::Date(int month, int day, int year){

this->month = month;

this->day = day;

this->year = year;

}

int Date::getMonth(){

return month;

}

int Date::getDay(){

return day;

}

int Date::getYear(){

return year;

}

void Date::setMonth(int month){

this->month = month;

}

void Date::setDay(int day){

this->day = day;

}

void Date::setYear(int year){

this->year = year;

}

string Date::toString(){

string ans = to_string(month)+"/";

ans += to_string(day)+"/";

ans += to_string(year);

return ans;

}

Kindly check the code output below.

4 0
3 years ago
Other questions:
  • Using tracking code, google analytics can report on data from which systems?
    7·1 answer
  • A(n) ____________ is a private data network that creates secure connections over regular internet lines.
    14·1 answer
  • The ______________________ is the part of the ip address that is the same among computers in a network segment.
    9·1 answer
  • What do you call the combination of title, description, tags, and thumbnail?
    6·1 answer
  • a) What are the 'interrupts' in a computer system? Describe the approaches to deal with multiple interrupts in a system.b) Analy
    12·1 answer
  • What is an ISP?<br> in computer Networking
    11·2 answers
  • А.<br> is the highest education degree available at a community college.
    6·1 answer
  • Gregory Yob is associated with which of these games?
    7·2 answers
  • Yo who do u add a pic on here
    13·1 answer
  • Help me please. I dont really understand this.
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!