Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用循环打印每个月租金,阈值_Java_Loops_Threshold - Fatal编程技术网

Java 使用循环打印每个月租金,阈值

Java 使用循环打印每个月租金,阈值,java,loops,threshold,Java,Loops,Threshold,使用循环打印阵列中低于用户输入阈值的每个月租金 这是我从讲师那里得到的一个问题,我需要帮助,因为我根本不知道从哪里开始。这是我完整的程序代码,这是最后一个案例 import java.util.Scanner ; public class jakeGrim { public static void main(String[] args) { // Local variable int option;

使用循环打印阵列中低于用户输入阈值的每个月租金

这是我从讲师那里得到的一个问题,我需要帮助,因为我根本不知道从哪里开始。这是我完整的程序代码,这是最后一个案例

import java.util.Scanner ;
public class jakeGrim {

  public static void  main(String[] args) {
                // Local variable

                int option;
                String squareFootage="";

                int noBed = 0;

                double totalSum =0;

                String propertyCode="";

                String propertyType="";

                String threshold="";


                Scanner input = new Scanner( System.in );
                Scanner user_input = new Scanner( System.in );
                double[] array = new double[12]; 

  do{
            // Display menu graphics
            System.out.println(" ");
            System.out.println("|  *****Rental Menu*******   |");
            System.out.println("|        1. Enter rental property Details     ");
            System.out.println("|        2. Enter monthly rent ( 12 Months )       ");
            System.out.println("|        3. Display Annual Rent");
            System.out.println("|        4. Display rental report       ");
            System.out.println("|        5. Display Monthly rents falling below a certain threshold       ");
            System.out.println(" ");
            System.out.println(" Please Select an option: ");
            option = input.nextInt();


  {

    switch (option) {


   case 1:


            System.out.println("Enter Rental Details: ");
            System.out.println("Property Code:            ");
            propertyCode = user_input.next();
            System.out.println("Property Type:            ");
            propertyType = user_input.next();
            System.out.println("Square Footage:           ");
            squareFootage = user_input.next();
            System.out.println("Number Of bedrooms        ");
            noBed = input.nextInt();
            break;


      case 2:

     {
         Scanner keyboardScanner = new Scanner(System.in); 

         for (int i = 0; i < 12; i++) {
          System.out.println("Enter Rental for month[" +( i +1)+ "]");
          array[i] = keyboardScanner.nextDouble();
}




        //So now, we need to do something with that array and sum up all the values in that array. 
        for (int i = 0; i < array.length; i++){
          System.out.println(array[i]);

         totalSum += array[i];
}
}




 break;


     case 3:
         System.out.println("The annual rent for propery code "+propertyCode+" is:  " +(totalSum));


break;

    case 4:

        System.out.println(" Property Code:      "+propertyCode);
        System.out.println(" Property Type:      "+propertyType);
        System.out.println(" Square Footage:     "+squareFootage);
        System.out.println(" Number of Bedrooms: "+noBed);
        System.out.println("");
        System.out.println("");
        for(int i = 0; i<12; i++)
            System.out.println("Rental for month " + (i+1) + " : " + array[i]);


    case 5:

         Scanner user_input = new Scanner( System.in );

        System.out.println("Enter the Rental Threshold: ");
        threshold = user_input.next();

        System.out.println("


    break;
    default:
        System.out.println("Invalid selection");
      break; 
     }
  }
}while (option!=0);
}
}
import java.util.Scanner;
公共课{
公共静态void main(字符串[]args){
//局部变量
int选项;
字符串平方英尺=”;
int noBed=0;
双倍总和=0;
字符串propertyCode=“”;
字符串属性类型=”;
字符串阈值=”;
扫描仪输入=新扫描仪(System.in);
扫描仪用户输入=新扫描仪(System.in);
double[]数组=新的double[12];
做{
//显示菜单图形
System.out.println(“”);
System.out.println(“|******租赁菜单**********”);
System.out.println(“| 1.输入租赁物业详细信息”);
System.out.println(“| 2.输入月租金(12个月)”;
System.out.println(“3.显示年租金”);
System.out.println(“| 4.显示租赁报告”);
System.out.println(“5.显示低于某个阈值的月租金”);
System.out.println(“”);
System.out.println(“请选择一个选项:”);
option=input.nextInt();
{
开关(选件){
案例1:
System.out.println(“输入租金明细:”);
System.out.println(“属性代码:”);
propertyCode=user_input.next();
System.out.println(“属性类型:”);
propertyType=user_input.next();
System.out.println(“平方英尺:”);
平方英尺=用户输入。下一步();
系统输出打印号(“卧室数量”);
noBed=input.nextInt();
打破
案例2:
{
扫描仪键盘扫描仪=新扫描仪(System.in);
对于(int i=0;i<12;i++){
System.out.println(“输入月份租金[”+(i+1)+“]);
数组[i]=keyboardScanner.nextDouble();
}
//现在,我们需要对这个数组做些什么,并将数组中的所有值相加。
for(int i=0;i对于(int i=0;i嗯,您的程序有几个缺陷,应该加以改进以获得更好的性能

  • switch之前不需要大括号。因此,删除switch语句之前的大括号
    {

  • 同样,在case-2的
    break
    语句之前,不需要在case-2和
    }
    中使用大括号
    {
    。最好保持原样

  • 在删除以前的数据后,在您的
    案例5:
    中添加这些代码行

    case 5:
       //  Scanner user_input = new Scanner( System.in );
    System.out.println("Enter the Rental Threshold: ");
    threshold = user_input.next();
    for(int i=0;i<array.length;i++){
    if(Integer.valueOf(threshold)>array[i])
    System.out.println("Month "+(i+1)+" has the rent falling below the threshold range as the rent is "+array[i]);
    }
    System.out.println("");
    break;
    
    案例5:
    //扫描仪用户输入=新扫描仪(System.in);
    System.out.println(“输入租金阈值:”);
    阈值=用户输入。下一步();
    对于(int i=0;iarray[i])
    System.out.println(“月”+(i+1)+”的租金低于阈值范围,因为租金为“+array[i]);
    }
    System.out.println(“”);
    打破
    

  • 最后,您只需编辑do while条件,将其设置为
    do{…}while(option>=1&&optionExplain您的问题清楚…如果您“根本不知道从哪里开始”,那么你的问题不适合堆栈溢出。@BlorgBeard这不是一个在编程时帮助那些需要它的人的网站吗?对编码是否陌生?@JakeGrim你应该试着更好地解释为什么你的程序目前不能工作(你期望什么输出?你得到什么?)和。不,Jake,不是。这是一个“专业和热心的程序员”来询问和回答特定的编程相关问题。请查看。特别是,“不要问……你没有试图找到答案的问题(展示你的工作!)“@JakeGrim现在我已经给了你答案,请把答案投上一票,并在验证其正确性后接受它,否则下次就没有帮助了!”现在我已经给了你答案-->现在,你真的认为这在学术环境中可以接受吗?更重要的是,你认为为他修改代码是在帮他忙吗?此外,你可以更好地解释你的更改,而不是说“做这个,这个,这个”。当你被告知要在没有被告知原因的情况下进行更改时,很难了解。但说真的。不要为他们做任何人的工作。这对他们没有帮助,而且会让人们对堆栈溢出的用途产生错误的想法。@user3580294很抱歉,谢谢你提醒。这是我给出的最后一个答案,因为OP真的很关心w关于这个问题。另见他的评论,他的问题也涉及代码。但是,下次没有真正的帮助!“真的关心这个问题”不是为他们做工作的理由。不管他们有多关心,他们都有责任做他们的工作。是的,我读了他的评论,是的,他的问题有代码。这并不意味着你应该提供代码让他复制/粘贴。不过,你的意图很好。好@user3580294,我会从下一次
    
           import java.util.Scanner;
           public class jakeGrim {
           public static void main(String[] args) {
           int option;
           String squareFootage="";
           int noBed = 0;
           double totalSum =0;
           String propertyCode="";
           String propertyType="";
           String threshold="";
           Scanner input = new Scanner( System.in );
           Scanner user_input = new Scanner( System.in );
           double[] array = new double[12]; 
           do{
            // Display menu graphics
            System.out.println(" ");
            System.out.println("|  *****Rental Menu*******   |");
            System.out.println("|        1. Enter rental property Details     ");
            System.out.println("|        2. Enter monthly rent ( 12 Months )       ");
            System.out.println("|        3. Display Annual Rent");
            System.out.println("|        4. Display rental report       ");
            System.out.println("|        5. Display Monthly rents falling below a certain threshold       ");
            System.out.println(" ");
            System.out.println(" Please Select an option: ");
            option = input.nextInt();
    
              switch (option){
            case 1:
            System.out.println("Enter Rental Details: ");
            System.out.println("Property Code:            ");
            propertyCode = user_input.next();
            System.out.println("Property Type:            ");
            propertyType = user_input.next();
            System.out.println("Square Footage:           ");
            squareFootage = user_input.next();
            System.out.println("Number Of bedrooms        ");
            noBed = input.nextInt();
            break;
    
            case 2:
    
            Scanner keyboardScanner = new Scanner(System.in); 
            for (int i = 0; i < 12; i++) {
            System.out.println("Enter Rental for month[" +( i +1)+ "]");
            array[i] = keyboardScanner.nextDouble();
             }
           //So now, we need to do something with that array and sum up all the values in that array. 
            for (int i = 0; i < array.length; i++){
             System.out.println(array[i]);
            totalSum += array[i];
            }
            break;
    
            case 3:
            System.out.println("The annual rent for propery code "+propertyCode+" is:  " +totalSum);
            break;
    
            case 4:
            System.out.println(" Property Code:      "+propertyCode);
            System.out.println(" Property Type:      "+propertyType);
            System.out.println(" Square Footage:     "+squareFootage);
            System.out.println(" Number of Bedrooms: "+noBed);
            System.out.println("");
            System.out.println("");
            for(int i = 0; i<12; i++)
            System.out.println("Rental for month " + (i+1) + " : " + array[i]);
            break;
    
            case 5:
            //    Scanner user_input = new Scanner( System.in );
            System.out.println("Enter the Rental Threshold: ");
            threshold = user_input.next();
            for(int i=0;i<array.length;i++){
            if(Integer.valueOf(threshold)>array[i])
            System.out.println("Month "+(i+1)+" has the rent falling below the threshold range as the rent is "+array[i]);
            }
            System.out.println("");
            break;
    
            default:
            System.out.println("Invalid selection");
            break; 
    
           }
           } while (option>=1 && option<=5);
         }
        }