Created
February 17, 2014 17:53
-
-
Save Yegorov/9055576 to your computer and use it in GitHub Desktop.
Java lab 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lab5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="CompilerConfiguration"> | |
<option name="DEFAULT_COMPILER" value="Javac" /> | |
<resourceExtensions /> | |
<wildcardResourcePatterns> | |
<entry name="!?*.java" /> | |
<entry name="!?*.form" /> | |
<entry name="!?*.class" /> | |
<entry name="!?*.groovy" /> | |
<entry name="!?*.scala" /> | |
<entry name="!?*.flex" /> | |
<entry name="!?*.kt" /> | |
<entry name="!?*.clj" /> | |
</wildcardResourcePatterns> | |
<annotationProcessing> | |
<profile default="true" name="Default" enabled="false"> | |
<processorPath useClasspath="true" /> | |
</profile> | |
</annotationProcessing> | |
</component> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="CopyrightManager"> | |
<settings default=""> | |
<module2copyright /> | |
</settings> | |
</component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false"> | |
<file url="file://$PROJECT_DIR$/src/lab/yegorov/Main.java" charset="UTF-8" /> | |
</component> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="EntryPointsManager"> | |
<entry_points version="2.0" /> | |
</component> | |
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK"> | |
<output url="file://$PROJECT_DIR$/out" /> | |
</component> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/Lab5.iml" filepath="$PROJECT_DIR$/Lab5.iml" /> | |
</modules> | |
</component> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="DependencyValidationManager"> | |
<state> | |
<option name="SKIP_IMPORT_STATEMENTS" value="false" /> | |
</state> | |
</component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="VcsDirectoryMappings"> | |
<mapping directory="" vcs="" /> | |
</component> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="JAVA_MODULE" version="4"> | |
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |
<exclude-output /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
</component> | |
</module> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IntelliJ API Decompiler stub source generated from a class file | |
// Implementation of methods is not available | |
package lab.yegorov; | |
public class Main { | |
public Main() { /* compiled code */ } | |
public static void main(java.lang.String[] args) { /* compiled code */ } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IntelliJ API Decompiler stub source generated from a class file | |
// Implementation of methods is not available | |
package lab.yegorov; | |
class ReplaceChar { | |
private java.lang.String inputString; | |
private char b; | |
public ReplaceChar(java.lang.String inputString, char b) { /* compiled code */ } | |
public java.lang.String toConvert() { /* compiled code */ } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lab.yegorov; | |
import java.util.Arrays; | |
import java.util.Vector; | |
/** | |
* Created by AdminPC on 14.02.14. | |
*/ | |
/* | |
Задание на лабораторную работу: | |
1. Разработать в программе следующие классы: | |
- класс, содержащий функцию main; | |
- класс для методов работы со строками; | |
- класс для методов тестирования, производный от класса основной программы. | |
2. Создать объекты классов программы и тестирования в функции main(). | |
Все классы описать внутри отдельного пакета. | |
Тесты должны запускаться вместе c тестами остальных лабораторных работ. | |
3. Выполнить и протестировать программу. | |
Variant 3. Задана строка a. Преобразовать каждое слово в строке так, | |
чтобы все предыдущие вхождения его последней буквы были заменены на заданный символ b. | |
Пример | |
a=”минимум”,b=”.” => rez = “.ини.ум”. | |
*/ | |
public class Main { | |
public static void main(String args[]) { | |
ReplaceChar t = new ReplaceChar("минимум - привев 1111 minimum Hello,,--\\ world tvtvvvht", '.');//Hello,,--\ world tvtvvvht | |
System.out.println("минимум - привев 1111 minimum Hello,,--\\ world tvtvvvht"); | |
System.out.println(t.toConvert()); | |
} | |
} | |
class ReplaceChar { | |
private String inputString; | |
private char b; | |
public ReplaceChar(String inputString, char b) { | |
this.inputString = inputString; | |
this.b = b; | |
} | |
public String toConvert() { | |
Vector<String> word = new Vector<String>(); | |
word.addAll(Arrays.asList(inputString.split("[ ,.?!:;\\\\\\-0-9]"))); | |
word.removeAll(Arrays.asList("")); //удаляем пустые строки | |
word.trimToSize(); | |
Vector<String> punct = new Vector<String>(); | |
punct.addAll(Arrays.asList(inputString.split("\\p{L}"))); | |
punct.removeAll(Arrays.asList("")); //удаляем пустые строки | |
punct.trimToSize(); | |
char endChar; | |
int endNum; | |
StringBuilder strBuild; | |
String rezult = new String(""); | |
for(int it = 0; it < word.size(); ++it) { | |
endNum = (word.elementAt(it)).length() - 1; | |
endChar = (word.elementAt(it)).charAt(endNum); | |
strBuild = new StringBuilder(word.elementAt(it)); | |
for(int i = endNum-1; i >= 0; --i) { | |
if((strBuild.charAt(i)) == endChar) | |
strBuild.setCharAt(i,b); | |
} | |
word.remove(it); | |
word.add(it,strBuild.toString()); | |
} | |
for(int i = 0, j = 0; i < word.size(); ++i) { | |
if(j<punct.size()) | |
rezult += word.elementAt(i) + punct.elementAt(j++); | |
else | |
rezult += word.elementAt(i); | |
} | |
return rezult; | |
} | |
} | |
class ReplaceCharTest extends ReplaceChar { | |
public ReplaceCharTest() { | |
super("sometext",'a'); | |
} | |
//TODO testing | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment