Write a Java application that asks a user to enter the data of a Person instance
ID: 639163 • Letter: W
Question
- Write a Java application that asks a user to enter the data of a Person instance: name and year_of_birth and then displays a message showing the age of the person. If the value of year_of_birth>2014 or year_of_birth<1900 prompt the user to reenter the value of year_of_birth and wait for the new value. Be sure your code compiles and runs as expected. Name your Java file Yournamehw2a.java.
- Write a Java interface named Searchable with two abstract methods: one named Way2Search that returns a String and another named MaxTime that returns an Integer. Be sure your code compiles and runs as expected. Name your Java file Searchable.java.
Explanation / Answer
Answer for 1 is:
class Yournamehw2a{
int Year;
String name;
Scanner sc=new Scanner();
System.out.println("Enter Name");
name=sc.readLine();
System.out.println("Enter Year");
age=sc.nextInt();
if(Year>2014||Year<1900){
System.out.println("Please re-enter your Date of Birth");
}
}
Answer for 2 is:
public interface Searchable {
public String Way2Search();
public Integer MaxTime();
}
class A implements Searchable {
...
public String way2Search() {
//implement this method in one way here
}
public Integer maxTime() {
//implement this method in one way here
}
}
class B implements Searchable {
...
public String way2Search() {
//implement this method in a different way here
}
public Integer maxTime() {
//implement this method in a different way here
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.