+ 1

Household income using java array and method

These coding have error on line total=income*siblings, can anyone help me pleaseeee import java.util.Scanner; public class PoorRich { public static void main(String[]args){ double total; Scanner input= new Scanner(System.in); System.out.println("enter the number of siblings:"); int siblings=input.nextInt(); System.out.println("enter income of the family:"); for(int i=0; i<siblings; i++) { double income = input.nextDouble(); } total = income * siblings; group(total); } public static void group(double total){ if(total>=10000.00){ System.out.println("rich"); } else{ System.out.println("poor"); } } }

9th Jan 2023, 1:18 PM
Aenul
Aenul - avatar
13 Answers
+ 4
import java.util.Scanner; public class PoorRich { public static void group(double total){ if(total>=10000.00){ System.out.println("rich"); } else{ System.out.println("poor"); } } public static void main(String[] args){ double total=0; Scanner input= new Scanner(System.in); System.out.println("enter the number of siblings:"); int siblings=input.nextInt(); double[] income = new double[siblings]; System.out.println("enter income of the family:"); for(int i=0; i<siblings; i++) { income[i] = input.nextDouble(); total +=income[i]; } group(total); } } //I test this check it once working 100% //For execution it asks input lines for example: "5 8000 4000 6000 3000 1000" then submit for the 5 member of total: 22000 >10000 you will get output as rich
9th Jan 2023, 4:57 PM
K Varun Bala Surya
K Varun Bala Surya - avatar
+ 2
All the best👌
9th Jan 2023, 5:09 PM
K Varun Bala Surya
K Varun Bala Surya - avatar
+ 2
Hey i changed total=total+income[i]; Now for 3 siblings 2000,1000,4500 total is 7500 the output is poor
9th Jan 2023, 5:15 PM
K Varun Bala Surya
K Varun Bala Surya - avatar
+ 2
Here it is You are giving 3 siblings Then after in array you are specifically income for each sibling Income[1st sibling,2 sib, 3 sib]=[2000,1000,4500] Total will be 2000+1000+4500 But 7500 is less than 10000 So output is poor
9th Jan 2023, 5:22 PM
K Varun Bala Surya
K Varun Bala Surya - avatar
+ 1
but it show error when i put [size_of_array]; public class PoorRich { public static void main(String[]args){ double total; Scanner input= new Scanner(System.in); System.out.println("enter the number of siblings:"); int siblings=input.nextInt(); double[]income = new double[size_of_array]; System.out.println("enter income of the family:"); for(int i=0; i<siblings; i++) { income[i] = input.nextDouble(); } total = income * siblings; group(total); } public static void group(double total){ if(total>=10000.00){ System.out.println("rich"); } else{ System.out.println("poor"); } } } like this?
9th Jan 2023, 3:00 PM
Aenul
Aenul - avatar
+ 1
Aaaaa i dont get it😭😔 why we must specify array when user already enter the number of siblings?
9th Jan 2023, 4:30 PM
Aenul
Aenul - avatar
+ 1
It still have error on total = income*siblings; group(total);
9th Jan 2023, 4:32 PM
Aenul
Aenul - avatar
+ 1
It's work, but double and int cant be solved, right? So, I need to change the datatype?
9th Jan 2023, 4:47 PM
Aenul
Aenul - avatar
+ 1
Anyways thank you muchh because helping me🙆🏻‍♀️ u are the bestt👍🏼
9th Jan 2023, 4:48 PM
Aenul
Aenul - avatar
+ 1
Bro i almost cry😭😭 THANK YOUU
9th Jan 2023, 5:01 PM
Aenul
Aenul - avatar
+ 1
No bro i am new to solo learn i wanted to answer correctly atleast one question 👍 enjoy learning
9th Jan 2023, 5:06 PM
K Varun Bala Surya
K Varun Bala Surya - avatar
+ 1
Yeahh today i have a test, wish me luck 😃
9th Jan 2023, 5:08 PM
Aenul
Aenul - avatar
+ 1
Can i know why total? oh yea my brain doesnt work at this time haha😌 sorry sorry
9th Jan 2023, 5:19 PM
Aenul
Aenul - avatar