gpt4 book ai didi

java - 编程作业出现问题农场生产

转载 作者:行者123 更新时间:2023-11-29 09:10:25 24 4
gpt4 key购买 nike

<分区>

开发一个自上而下的设计并编写一个程序,以逐个农场为合作农场组制作美味爆米花生产的条形图。

  • 程序的输入是一系列数据集,每行一个,每组代表一个农场的产量。
  • 每个数据集都包含一个农场的名称。后跟一个逗号和一个或多个空格,代表种植英亩的十进制数,一或更多空格,以及代表品脱 jar 数的整数为该农场生产的爆米花。
  • 输出是一个条形图,标识每个农场并显示其每英亩 Jade 米产量(以品脱计)。
  • 每个农场的输出是一行,带有农场名称从一条线上的第一列开始,条形图从第 30 列。条形图中的每个标记代表 25 品脱 jar 每英亩爆米花。
  • 今年的生产目标是每英亩 500 jar 。竖条对于产量不高的农场,应该出现在图表中达到这个目标,有生产的农场使用特殊标记每英亩大于或等于 500 jar 。

例如,给定输入文件

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

输出将是:

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. ************ |

这是我已经运行并打印正确格式的代码,但它有异常错误。我试图将一个字符串分成农场名称,然后是双英亩,最后是一个 int jar 。输入文件是

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

所有空格的原因是我希望它只读取包含数据的行。

这是我的源代码

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

public class Popcorn
{

public static void main(String args[])throws Exception
{

printHeading();

System.out.print("Input file name you want to read from: ");

Scanner in = new Scanner(System.in);

String fileName = in.next(); //declares fileName a string that uses in as input

Scanner input = new Scanner(new FileReader(fileName)); //Declares input as the fileName and reads the file in

int jars;
double acres;
String amount;
String farmName;
System.out.println();
System.out.println("\t\t\tPopcorn Co-op");
System.out.println();
System.out.println("\t\t\t\tProduction in Hundreds");
System.out.println("\t\t\t\tof Pint Jars per Acre");
System.out.println("Farm Name\t\t\t 1 2 3 4 5 6");
System.out.println("\t\t\t\t---|---|---|---|---|---|");


while (input.hasNextLine())
{


String inputLine = input.nextLine();

if (inputLine.isEmpty())
{

}
else
{
farmName = inputLine.substring(0,inputLine.indexOf(','));
String inputLine2 = inputLine.substring(inputLine.indexOf(','),inputLine.length());
Scanner line = new Scanner(inputLine2);
acres = line.nextDouble();
jars = line.nextInt();
System.out.println(farmName + jars + acres);

}

}
}

private static void printHeading(){


System.out.println("Name"); //this assigns what printHeading will print
System.out.println("CSC 201-55468 Section 01PR");
System.out.println("Fall 2012");
System.out.println("Popcorn Project");
System.out.println();
}

}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com