Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Answer in java, Fully Commented Ernie and Bert are arguing about which of them i

ID: 3687949 • Letter: A

Question

Answer in java, Fully Commented

Ernie and Bert are arguing about which of them is older, and they need your help to figure it out. Write a Java Program that asks the user for the birthdays of both Ernie and Bert, and responds by indicating which person is older (or if they are the same age). Here's a demonstration, copy/pasted from the Console window.

Note that the user typed the numbers that are displayed using green colored text.
You should do some problem solving before you start. What will your algorithm be? Having a

good plan before you start will make you more productive. Your task involves the following steps:

Before you start designing your program, you might think that there are 3 possibilities: 2 cases in which one person is older, and 1 case that the people are the same
age. However, there are actually more than 3 possible scenarios that you will have to consider in your design, and your program must answer correctly for all of them. We call such scenarios "test cases", especially if we use them to test the hypothesis that a program is correct.

Hint: You'll need 7 test cases (examples) to cover the possibilities. If you can't imagine why you need 7 test cases, you haven't fully understood the problem.
Note: Assume your user will type integers as requested. You do not have to worry about the user entering other kinds of data, like characters or floats.

Note: You may assume that all data given by the user is error-free; they will not try to enter a day beyond the end of the month (ex: 2 40 [Feb 40]), a month that does not exist, a negative year, or any other kind of error like that.

Starting from the Hello World template in Eclipse, write a program that behaves the same way as the above example. It must ask for 2 birth dates, and must produce a statement about which person is older.

Show that your program gets all your test cases right. Run your program once for each test case, and copy/paste the Console window text into a document to submit for grading.

Explanation / Answer

import java.util.*;
import java.io.*;
public class HelloWorld{
     public static void main(String []args){
        Scanner read=new Scanner(System.in);
        System.out.print("Please enter Ernie's birthday: ");
        String bday1=read.nextLine();
        System.out.print(" Please enter Bert's birthday: ");
        String bday2=read.nextLine();
        String tokens1[]=bday1.split(" ");
        String tokens2[]=bday2.split(" ");
        for(int i=0;i<3;i++)
        {
            if(Integer.parseInt(tokens1[i]) < Integer.parseInt(tokens2[i]))
            {
            System.out.println("Ernie is elder");
            break;
            }
            else if(Integer.parseInt(tokens1[i]) > Integer.parseInt(tokens2[i]))
            {
            System.out.println("Bert is elder");
            break;
            }
        }
     }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote