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

Write your solution in HistoPrint.java When you are finished, submit the file Hi

ID: 3812324 • Letter: W

Question

Write your solution in HistoPrint.java

When you are finished, submit the file HistoPrint.java

IMPORTANT: Double check that you have submitted the correct file. this is part of the assignment.

This method print a simple graph based on user-provided data.

Write a complete Java program with the following methods:

A method that takes no parameters and returns a String.
Request this String from the user, it is the title of the graph.

A method that takes no parameters and returns an ArrayList of Integers.
Ask the user to enter a list of integers, they can enter as many integers as they like.
The method returns these in the ArrayList.

A method that takes a String (the graph title) and an ArrayList of Integers as parameters.
This method prints the title and a graph to the command line using the ArrayList of Integers as data.
Each value in the ArrayList is the number of stars to print on that line.
Each element in the ArrayList is a separate line in the graph.
See the example below.

The user enters “My Graph” as the title
The user enters: 3, 5, 6, 2 as the data
The app outputs the following:

My Graph
***
*****
******
**

Call all three methods from the main method using appropriate parameter passing.

Explanation / Answer

JAVA PROGRAM :


import java.util.*;
import java.lang.*;
import java.io.*;


class HistoPrint{
   public static String getTitle(){
       Scanner obj = new Scanner(System.in);
       System.out.println("Please enter the title for the string");
       return obj.next();
   }
   public static ArrayList getList() throws Exception{
       System.out.println("Enter the list seperated by commas");
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       String str[] ;
       str = br.readLine().trim().split(",");
       ArrayList<Integer> al = new ArrayList();
       for(String x : str){
           al.add(Integer.parseInt(x));
       }
       return al;
   }
   public static void print(String title, ArrayList<Integer> list){
       System.out.println(title);
       for(int x : list){
           for(int i=0;i<x;i++){
               System.out.print("*");
           }
           System.out.println();
       }
   }
   public static void main (String[] args) throws java.lang.Exception
   {
       // your code goes here
       String title = getTitle();
       ArrayList<Integer> list = getList();
       print(title,list);
   }
}

OUTPUT :

D:>java HistoPrint
Please enter the title for the string
JAVA_PROGRAM
Enter the list seperated by commas
2,5,3,4
JAVA_PROGRAM
**
*****
***
****