Answer the question
In order to leave comments, you need to log in
How to turn the code into a class with "features"?
There is a code that asks you to enter a person's first and last name and his birthday (in three digits) and then determines the zodiac sign
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m, d, y, n, f;
String z=" ";
System.out.print("Ведите имя и фамилию: ");
String name = in.nextLine();
System.out.println("Скажите день рождения");
d=in.nextInt();
System.out.println("Скажите месяц рождения");
m=in.nextInt();
System.out.println("Скажите год рождения");
y=in.nextInt();
switch (m) {
case 1:
if (d <= 19)
z = "Козерог";
else
z = "Водолей";
break;
case 2:
if (d <= 18)
z = "Водолей";
else
z = "Рыбы";
break;
case 3:
if (d <= 20)
z = "Рыбы";
else
z = "Овен";
break;
case 4:
if (d <= 19)
z = "Овен";
else
z = "Телец";
break;
case 5:
if (d <= 20)
z = "Телец";
else
z = "Близнецы";
break;
case 6:
if (d <= 21)
z = "Близнецы";
else
z = "Рак";
break;
case 7:
if (d <= 22)
z = "Рак";
else
z = "Лев";
break;
case 8:
if (d <= 22)
z = "Лев";
else
z = "Дева";
break;
case 9:
if (d <= 22)
z = "Дева";
else
z = "Весы";
break;
case 10:
if (d <= 22)
z = "Весы";
else
z = "Скорпион";
break;
case 11:
if (d <= 22)
z = "Скорпион";
else
z = "Стрелец";
break;
case 12:
if (d <= 21)
z = "Стрелец";
else
z = "Козерог";
break;
}
System.out.println(name+" дата рождения: "+d+"."+m+"."+y);
System.out.println("Знак зодиака: "+z);
}
}
Answer the question
In order to leave comments, you need to log in
Hello!
I recommend first of all to study the basics of OOP and Java development.
Code data must be with "private" specifier
switch (m) {
case 1:
if (d <= 19)
z = "Козерог";
else
z = "Водолей";
break;
case 2:
if (d <= 18)
z = "Водолей";
else
z = "Рыбы";
break;
case 3:
if (d <= 20)
z = "Рыбы";
else
z = "Овен";
break;
case 4:
if (d <= 19)
z = "Овен";
else
z = "Телец";
break;
case 5:
if (d <= 20)
z = "Телец";
else
z = "Близнецы";
break;
case 6:
if (d <= 21)
z = "Близнецы";
else
z = "Рак";
break;
case 7:
if (d <= 22)
z = "Рак";
else
z = "Лев";
break;
case 8:
if (d <= 22)
z = "Лев";
else
z = "Дева";
break;
case 9:
if (d <= 22)
z = "Дева";
else
z = "Весы";
break;
case 10:
if (d <= 22)
z = "Весы";
else
z = "Скорпион";
break;
case 11:
if (d <= 22)
z = "Скорпион";
else
z = "Стрелец";
break;
case 12:
if (d <= 21)
z = "Стрелец";
else
z = "Козерог";
break;
}
System.out.println(name+" дата рождения: "+d+"."+m+"."+y);
System.out.println("Знак зодиака: "+z);
}
int m, d, y, n, f;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question