The file containing the JAVA files, pseudocode file and doc file that have written for this lab.
JAVA Program with comments:
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
public class main {
//method for reading input from file
public static String[] input(String filename){
try {
File file = new File(filename);
Scanner reader = new Scanner(file);
ArrayList<String> lines = new
ArrayList<String>();
//tokenize each line in date and name and add to arraylist
while (reader.hasNextLine()) {
String line = reader.nextLine();
String[] tokens = line.split("\t");
lines.add(tokens[0]);
lines.add(tokens[1]);
}
String[] str = new String[lines.size()];
int i = 0;
//putting lines into array of strings
for(String line:lines){
str[i++] = line;
}
return str;
}catch (IOException e){ //if there is an error while reading
file
System.out.println("File Read error occurred.");
}
return new String[1];
}
//method for writing infor to output file
public static void output(String filename, String[] info){
try {
FileWriter fr = new FileWriter(filename);
//writing strings from array to the file
for (int i = 0; i < info.length; i = i + 2) {
fr.write(info[i] + "\t" + info[i + 1] + "\n");
}
fr.close();
}catch (IOException e){ //if error occur during writing to
file
System.out.println("File Write error occurred.");
}
}
//method for sorting string array by month
public static String[] sortByMonth(String[] info){
String[] str = info;
for(int i=0;i<info.length;i=i+2){
for(int j=0;j<info.length-i-2;j=j+2){
if(info[j].compareTo(info[j+2])>0){ //if next date is
lexicographically smaller than current then swap
String temp1=info[j],temp2=info[j+1];
info[j] = info[j+2];
info[j+1] = info[j+3];
info[j+2] = temp1;
info[j+3] = temp2;
}
}
}
return info; //return the sorted array
}
//method for sorting by name
public static String[] sortByName(String[] info){
for(int i=1;i<info.length;i=i+2){ //if next name is
lexicographically smaller than current then swap
for(int j=1;j<info.length-i-2;j=j+2){
if(info[j].compareTo(info[j+2])>0){
String temp1=info[j-1],temp2=info[j];
info[j-1] = info[j+1];
info[j] = info[j+2];
info[j+1] = temp1;
info[j+2] = temp2;
}
}
}
return info; //return the sorted array
}
//main method
public static void main(String[] args) {
String[] str =
input("C:\\Users\\achar\\IdeaProjects\\filehandling\\src\\input.txt");
output("SortedByName.txt", sortByName(str));
output("SortedByDate.txt", sortByMonth(str));
}
}
output files after running the program:
The file containing the JAVA files, pseudocode file and doc file that have written for this...
Need help writing a program that meets pseudocode and criteria . Txt File below input.txt file data 05 11/30/16 03 12/07/16 05 12/07/16 05 12/08/16 01 12/10/16 07 12/11/16 07 12/14/16 06 12/15/16 02 12/21/16 05 12/21/16 06 12/22/16 07 12/22/16 08 12/23/16 07 12/23/16 07 12/23/16 07 12/23/16 08 12/24/16 08 12/24/16 07 12/24/16 03 12/26/16 05 12/26/16 07 12/28/16 04 12/29/16 07 01/01/17 06 01/03/17 07 01/03/17 08 01/05/17 05 01/10/17 04 01/17/17 08 01/17/17 07 01/18/17 07...
Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART A PART B Assignment 1 #include <iostream> #include <string> #include <fstream> #include <iomanip> #include <stdio.h> #include <ctype.h> #include <string.h> #include <algorithm> using namespace std; /** This structure is to store the date and it has three integer fields **/ struct Date{ int day; int month; int year; }; /** This structure is to store the size of the box and it...
Random Sampling Written Homework 1. The table below lists students in an imaginary Statistics class, along with their identification numbers. Use your graphing calculator to select a random sample of 8s 01. Adrian 07, Gregg 08. Helern 13. Max 19. Stella Adrian07 Greg8 02. Betty 03. Carl 04. Diane 05. Earl ET11. Kar 14. Nicole 15. Oliver 16. Paxton 20. Trace 21. Una 22. Verle 12. Lucy 18. Rashid 17. Quentin 23. Wyatt 24. Xavier 06. Filene 2. The same...
Python help it is a grade 12 course def find astrological sign(month, date): (int, int)-str Given two int values represent ing a month and a date, return a 3-character string that gives us what star sign a person born in that month and on that date belongs to, Use the SIGNS string (already defined for you at the top of this file) to figure this out. NOTE FROM BOB: A lot of string slicing to do here. It looks like...
What is the major product for each reaction? Could you please draw the mechanism? JAN FEB MAR APR MAY 01 02 03 04 05 06 07 08 09 10 11 12 13 JUN 14 15 16 JUL AUG SEP O 17 18 19 20 21 22 23 24 25
please show all work and explain here is the data and explanation of 12.4 here is appendix D 12.12. * In Problem 12.4, find the value of x2. If the dice really are true, what is the probability of getting a value of X2this large or larger? Explain whether the evidence suggests the dice are loaded. (See Appendix D for the necessary probabili- ties.) 12.4.I throw three dice together a total of 400 times, record the number of sixes in...
Java code BIRTHDAY GRAPH5 4B Input Standard input Output Standard output Topic Array & Array Processing Birthday Graph Problem Description Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social E interaction among co-workers, foster friendship among classmates or even strengthen bond between E BOBO Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, UU candles with names, or it can be in the form of simple bar...
Code with Java using arrays and Scanner only ( input should end with 0 to terminate the program) Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social interaction among co-workers, foster friendship among classmates or even strengthen bond between families. Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, candles with names, or it can be in the form of simple bar chart to indicate the birthday...
price time month day year 149.3999939 1 01 02 13 146.5 2 01 03 13 147.3499908 3 01 04 13 150.3999939 4 01 07 13 148.1499939 5 01 08 13 147.8999939 6 01 09 13 149.6499939 7 01 10 13 153.3499908 8 01 11 13 153.3000031 9 01 14 13 152.5 10 01 15 13 153 11 01 16 13 155.5 12 01 17 13 156.3000031 13 01 18 13 148.5999908 14 01 22 13 150.3999939 15 01 23 13...
The code should work exactly the same as given example. The files: ---------------------------------------------------------------------------------------------------- -------- FILE NAME ------- album0 ---------- FILE ------- <album> 323 Licensed to Ill Beastie Boys 25.0 </album> <album> 70 Enter the Wu_Tang: 36 Cham... Wu Tang Clan 25.99 </album> turning to Alice, she went on, `What's your name, child?' and there stood the Queen in front of them, with her arms folded, <album> 115 Daydream Nation Sonic Youth 5.0 </album> <album> 414 52nd Street Billy Joel 25.75...