Question

Code with Java using arrays and Scanner only ( input should end with 0 to terminate...

Code with Java using arrays and Scanner only ( input should end with 0 to terminate the program)

Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social interaction among co-workers, foster friendship among classmates or even strengthen bond between families.

Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, candles with names, or it can be in the form of simple bar chart to indicate the birthday frequency for the month.

Birthday graph apps will come handy to tabulate birthdates by month especially for a large group. Your task is to write a program that reads a list of birthdates and display the birthday graph as shown in the sample output below.

Input

The input consists of a few test cases. For each test case, the first line of input is a positive integer N (N ≤ 100) which indicates the number of data in the test case. Each of the following N lines contains a valid date representing birthdays formatted as dd mm yyyy. Input is terminated by a test case where N is 0.

Output

For each test case, output a line in the format "Case #x:" where x is the case number (starting from 1), follow by the monthly birthday graph as shown in the sample output.

Sample Input

15
26 06 2007
27 09 2012
08 08 1995
02 01 2008
07 04 1999
25 10 2006
26 04 1995
09 02 2006
06 01 2010
05 02 2012
07 01 2014
12 05 2009
22 04 1997
24 08 2005
05 05 2006
10
15 12 2000
13 10 1997
29 06 1998
19 06 1996
03 01 1997
05 11 2000
18 02 1999
12 05 2000
29 11 1995
22 04 1998
0

Sample Output

Case #1:
Jan:***
Feb:**
Mar:
Apr:***
May:**
Jun:*
Jul:
Aug:**
Sep:*
Oct:*
Nov:
Dec:
Case #2:
Jan:*
Feb:*
Mar:
Apr:*
May:*
Jun:**
Jul:
Aug:
Sep:
Oct:*
Nov:**
Dec:*
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question, here is the complete code in JAva. Few things you need to do when running it.

Please keep a file by the name birthdays.txt (screenshot below) and then update the below line inside the main method. I kept the file name in my F drive so same way you too need to keep the file and then update the file path in the below line. Thats it.
String fileName = "F:\\birthdays.txt"; 

Here is the code in Java and the screenshot of the output. If you are satisfied with the solution, please rate the answer.

Thank You !


===========================================================================

import java.util.Scanner;

public class BirthdayGraph {

    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);
        int testCase = 0;
        int count = 0;
        do {

            count = scanner.nextInt();
            int months[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
            int day = 0, month = 0, year = 0;
            for (int i = 1; i <= count; i++) {
                day = scanner.nextInt();
                month = scanner.nextInt();
                year = scanner.nextInt();
                months[month - 1] += 1;
            }
            testCase += 1;
            if (count > 0) displayGraph(testCase, months);

        } while (count != 0);


    }

    private static void displayGraph(int testCase, int[] months) {
        System.out.println("Case #" + testCase + ":");
        String monthNames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
        for (int i = 0; i < months.length; i++) {

            System.out.print(monthNames[i] + ": ");
            for (int stars = 1; stars <= months[i]; stars++) {
                System.out.print("* ");
            }
            System.out.println();
        }
    }
}

=============================================================================

Add a comment
Know the answer?
Add Answer to:
Code with Java using arrays and Scanner only ( input should end with 0 to terminate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java code BIRTHDAY GRAPH5 4B Input Standard input Output Standard output Topic Array & Array Processing...

    Java code BIRTHDAY GRAPH5 4B Input Standard input Output Standard output Topic Array & Array Processing Birthday Graph Problem Description Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social E interaction among co-workers, foster friendship among classmates or even strengthen bond between E BOBO Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, UU candles with names, or it can be in the form of simple bar...

  • matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using...

    matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using any of the examples. Your function should work for all possible inputs as specified by the problem. Hard coding will result in significant point loss. (B) (28 Points) Function Name: birthday Party Input (2): (char) An Mx 11 array formatted with information about various birthdays (char) An MxN array of names Output (l): (char) A string containing information about the best birthday Function Description:...

  • Estimate the 100-year flood discharge and gauge height for Spring Creek in Houserville using the data...

    Estimate the 100-year flood discharge and gauge height for Spring Creek in Houserville using the data provided. First, calculate the Rank (1 being the flood with the greatest discharge) and Recurrence Time, using the formula RT-(n+1) m is the number of yearly peak flood data- 20 in this case, and m is the rank of the peak discharge), filling in the results for the table below. Rank Recurrence Time Discharge (cfs) 318 687 440 351 476 Year 1985 196 1987...

  • Date Gasoline Crude Oil Jan 01, 2010 2.031 79.07 Jan 08, 2010 2.124 82.34 Jan 15,...

    Date Gasoline Crude Oil Jan 01, 2010 2.031 79.07 Jan 08, 2010 2.124 82.34 Jan 15, 2010 2.079 80.06 Jan 22, 2010 2.010 76.62 Jan 29, 2010 1.942 73.94 Feb 05, 2010 1.885 74.57 Feb 12, 2010 1.908 73.88 Feb 19, 2010 2.031 78.25 Feb 26, 2010 2.042 79.22 Mar 05, 2010 2.127 80.19 Mar 12, 2010 2.154 81.76 Mar 19, 2010 2.150 81.44 Mar 26, 2010 2.118 80.65 Apr 02, 2010 2.191 83.01 Apr 09, 2010 2.238 85.66 Apr...

  • The code should work exactly the same as given example. The files: ---------------------------------------------------...

    The code should work exactly the same as given example. The files: ---------------------------------------------------------------------------------------------------- -------- FILE NAME ------- album0 ---------- FILE ------- <album> 323 Licensed to Ill Beastie Boys 25.0 </album> <album> 70 Enter the Wu_Tang: 36 Cham... Wu Tang Clan 25.99 </album> turning to Alice, she went on, `What's your name, child?' and there stood the Queen in front of them, with her arms folded, <album> 115 Daydream Nation Sonic Youth 5.0 </album> <album> 414 52nd Street Billy Joel 25.75...

  • I need the answer to #2 listed above. This is the code I have come up...

    I need the answer to #2 listed above. This is the code I have come up with, and it is wrong. I am new to this and need help. group by sust.cida Q2 (7 Points) Show customer id (CID) for customers who have spent 30,000 or more with the company in 2019. Money is considered "spent" when the entire work order is completed as recorded in workorder.completionDate. (Correct query will find customer 2). Use ONE SQL statement. select workarder.id from...

  • The file containing the JAVA files, pseudocode file and doc file that have written for this...

    The file containing the JAVA files, pseudocode file and doc file that have written for this lab. Preamble The file releasedates.txt contains a list of video games and their release dates. Each line of the file contains the release date, a tab character, and then the name. The list is currently totally unsorted. The object of today's lab is to write a series of methods that allow us to perform the following tasks: read contents from a file and store...

  • Python Coding problem

    Tracking the Shipment DatesRadan Logistics is a mid sized Shipping Company known for its Customer oriented delivery services. The Company Management intended to place an information kiosk in their Head Office which would help their Customers to fetch all the desired information with regards to their shipment. One such vital information that Customers would prefer to know is the details of the working days of the Company which would help them track their shipments.Help the Management write a program for...

  • Write a C++ program that will input data from a Comma-separated values (.csv) file and output som...

    Write a C++ program that will input data from a Comma-separated values (.csv) file and output some information about it. This program uses a csv file from Yahoo Finance (.csv) filename : SBUX.csv 1. Output the name of the ticker to the console screen (without the “.csv”) 2. Output the start date and end date that was found in the file 3. Output how many trading day(s) existed in the file 4. Prompt the use to input a number of...

  • Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART...

    Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART A PART B Assignment 1 #include <iostream> #include <string> #include <fstream> #include <iomanip> #include <stdio.h> #include <ctype.h> #include <string.h> #include <algorithm> using namespace std; /** This structure is to store the date and it has three integer fields **/ struct Date{    int day;    int month;    int year; }; /** This structure is to store the size of the box and it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT