ЗАДАЧА 13.11.01.
package com.javarush.test.level13.lesson11.home01;
/* Некорректные строки
Удали все некорректные строки в интерфейсе Button.
*/
public class Solution
{
public static void main(String[] args) throws Exception
{
System.out.println(SimpleObject.NAME);
System.out.println(Button.NAME);
}
interface SimpleObject
{
String NAME = "SimpleObject";
void onPress();
}
interface Button extends SimpleObject
{
final String NAME = "Submit";
}
}
ЗАДАЧА 13.11.02.
package com.javarush.test.level13.lesson11.home02;
/* Погода
1. В классе Today реализовать интерфейс Weather.
2. Подумай, как связан параметр String type с методом getWeatherType().
3. Интерфейсы Weather и WeatherType уже реализованы.
*/
public class Solution
{
public static void main(String[] args)
{
System.out.println(new Today(WeatherType.CLOUDY));
System.out.println(new Today(WeatherType.FOGGY));
System.out.println(new Today(WeatherType.FROZEN));
}
static class Today implements Weather
{
private String type;
Today(String type)
{
this.type = type;
}
@Override
public String toString()
{
return String.format("%s for today", this.getWeatherType());
}
@Override
public String getWeatherType()
{
return type;
}
}
}
package com.javarush.test.level13.lesson11.home02;
public interface Weather
{
String getWeatherType();
}
package com.javarush.test.level13.lesson11.home02;
public interface WeatherType
{
String CLOUDY = "Cloudy";
String FOGGY = "Foggy";
String FROZEN = "Frozen";
}
ЗАДАЧА 13.11.03.
package com.javarush.test.level13.lesson11.home03;
/* Чтение файла
1. Считать с консоли имя файла.
2. Вывести в консоль(на экран) содержимое файла.
3. Не забыть освободить ресурсы. Закрыть поток чтения с файла и поток ввода с клавиатуры.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.FileInputStream;
public class Solution
{
public static void main(String[] args) throws IOException
{
//add your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String read = reader.readLine();
InputStream inStream = new FileInputStream(read);
while(inStream.available() > 0)
{
int data = inStream.read();
char data1 = (char) data;
System.out.print(data1);
}
reader.close();
inStream.close();
}
}
ЗАДАЧА 13.11.04.
package com.javarush.test.level13.lesson11.home04;
/* Запись в файл
1. Прочесть с консоли имя файла.
2. Считывать строки с консоли, пока пользователь не введет строку "exit".
3. Вывести абсолютно все введенные строки в файл, каждую строчку с новой стороки.
*/
import java.io.*;
import java.util.ArrayList;
public class Solution
{
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String write = reader.readLine();
ArrayList<String> list = new ArrayList<>();
while(true)
{
String readString = reader.readLine();
if (readString.equals("exit"))
{
list.add(readString);
break;
}
list.add(readString);
}
FileWriter writer = new FileWriter(write);
for (String text : list)
{
writer.write(text);
writer.write(System.getProperty("line.separator"));
}
reader.close();
writer.close();
/*
OutputStream outStream = new FileOutputStream(write);
for (String text : list)
{
outStream.write(text.getBytes());
outStream.write(Integer.parseInt(System.getProperty("line.separator")));
}
reader.close();
outStream.close();
*/
}
}
ЗАДАЧА 13.11.05.
package com.javarush.test.level13.lesson11.home05;
/* Neo
1. Реализовать интерфейс DBObject в классе User.
2. Реализовать метод initializeIdAndName так, чтобы программа работала и выводила на экран "User has name Neo, id = 1".
3. Метод toString и метод main менять нельзя.
4. Подумай, что должен возвращать метод initializeIdAndName в классе User.
*/
public class Solution
{
public static void main(String[] args) throws Exception
{
System.out.println(Matrix.NEO);
}
static class Matrix
{
public static DBObject NEO = new User().initializeIdAndName(1, "Neo");
}
interface DBObject
{
DBObject initializeIdAndName(long id, String name);
}
static class User implements DBObject
{
long id;
String name;
@Override
public String toString()
{
return String.format("User has name %s, id = %d", name, id);
}
@Override
public DBObject initializeIdAndName(long id, String name)
{
this.name = name;
this.id = id;
return this;
}
}
}
Leave A Comment