Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello Sasha. I have done my homework on enums. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
README.md
pointer-enum.iml
./out
13 changes: 13 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Привет, выбери себе телефон из списка возможных: ");
PhoneShop.showPhoneList();
System.out.println("Просто напечатай нужный тебе телефон в форму ниже: ");
String writeYourPhone = in.nextLine();
PhoneShop.showPhone(PhoneShop.valueOf(writeYourPhone));

}
}
51 changes: 51 additions & 0 deletions src/PhoneShop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import com.sun.tools.javac.comp.Resolve;

public enum PhoneShop {
IPHONE4S("Iphone 4 s"),
IPHONE5("Iphone 5"),
IPHONE8PLUS("Iphone 8 Plus"),
LENOVOK4000("Lenovo K4000"),
SAMSUNGS9("Samsung s 9"),
MEIZUM3NOTE("Meizu m 3 NOTE");


private String phoneName;
private static PhoneShop[] phoneShops = PhoneShop.values();

PhoneShop(String phoneName) {
this.phoneName = phoneName;
}

@Override
public String toString() {
return phoneName;
}

static void showPhoneList() {
for (PhoneShop phoneNames : phoneShops) {
System.out.println(phoneNames.name());
}
}

static void showPhone(PhoneShop phoneName) {
switch (phoneName) {
case IPHONE4S:
System.out.println(phoneName.toString());
return;
case IPHONE5:
System.out.println(phoneName.toString());
return;
case IPHONE8PLUS:
System.out.println(phoneName.toString());
return;
case LENOVOK4000:
System.out.println(phoneName.toString());
return;
case SAMSUNGS9:
System.out.println(phoneName.toString());
case MEIZUM3NOTE:
System.out.println(phoneName.toString());
return;
}
}
}