mardi 3 mars 2015

I am trying to change the numbers to stars



Develop a top-down design and write a program to produce a bar chart of gourmet-popcorn production for a cooperative farm group on a farm-by-farm basis. The input to the program is a series of data sets, one per line, with each set representing the production for one farm. Each data set consists of the name of a farm followed by a comma and one or more spaces; a decimal number representing acres planted, one or more spaces; and an integer representing the number of pint jars of popcorn produced for that farm. The output is a bar chart that identifies each farm and displays its production in pints of corn per acre. The output is a single line for each farm, with the name of the farm starting in the first column on a line and the bar chart starting in column 30. Each mark in the bar chart represents 25-pint jars of popcorn per acre. The production goal for the year is 400 jars per acre. A vertical bar should appear in the chart for farms with production that does not meet this goal, and a special mark (#) is used for farms with production greater than or equal to 400 jars per acre. For example, given the input file Orville’s Acres, 114.8 43801 Hoffman’s Hills, 77.2 36229 Jiffy Quick Farm, 89.4 24812 Jolly Good Plantation, 183.2 104570 Organically Grown Inc., 45.5 14683 the output would be: Popcorn Co-op Production in Hundreds of Pint Jars per Acre Farm Name 1 2 3 4 5 6 ---|---|---|---|---|---| Orville's Acres ***************| Hoffman's Hills ***************#*** Jiffy Quick Farm *********** | Jolly Good Plantation ***************#****** Organically Grown Inc. ************ |


Here is my Source Code



import java.io.*;
import java.util.Scanner;


public class Popcorn {

public static void main(String [] args) throws IOException{
String farm ;
double acre = 0;
int jar = 0;

Scanner input = new Scanner (System.in);

System.out.print("Input the file name with .txt extention : "); // for the user to input the file name with .txt extesion.

File fileName = new File(input.nextLine());// Gets the File Name
while(!fileName.exists()) { // It will ask the user to enter the file name again if it is not in directory.
// Prompts for input file name
System.out.print("The file is not in this directory. Please re-enter the file name: ");
fileName = new File(input.nextLine()); //Gets the File Name
input = new Scanner (System.in); // Constructs File object
}

System.out.println(" Popcorn Co-op");
System.out.println(" Production in Hundreds");
System.out.println(" of Pint Jars per Acre");
System.out.println("Farm Name 1 2 3 4 5 6");
System.out.println(" ---|---|---|---|---|---|");

input = new Scanner (fileName);
while (input.hasNextLine()) {
String line = input.nextLine();
System.out.println(line); }



}
}



Aucun commentaire:

Enregistrer un commentaire