Answer to Question #316415 in Java | JSP | JSF for saphira

Question #316415

Create objec-oriented programming that well implement this principle:



"According to plato, a man should marry a woman who is half his age plus 7 years"




Create the following:



1. Two (2) classes (MyMainClass & TheOtherClass)



2. Two (2) mutator methods:



•setName - accepts a man's name then copies that name to the attribute "name"



•setAge - accepts a man's age then copies that age to the attribute "man_age"




3. Two (2) accessor method:



•getName (String) - returns the man name attribute "name"



•getWomanAge(int) - returns the woman's age attribute "woman_age"




Sample output:



Enter the man's name: Hansel



Enter the man's age: 36



Hansel should Mary a girl who's 25 years old.

1
Expert's answer
2022-03-23T13:45:22-0400
import java.util.Scanner;

class TheOtherClass{
    String name;
    int age;

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void getWomanAge() {
        System.out.print( getName() + "should Mary a girl who's " + ((age/2)+7) + " years old.");
    }
}

public class MyMainClass{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        TheOtherClass oth = new TheOtherClass();

        System.out.print("Enter the man's name: ");
        oth.setName(in.next());

        System.out.print("Enter the man's age:");
        oth.setAge(in.nextInt());

        oth.getWomanAge();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS