Requirements Create a program that interviews the users about their personal inf
ID: 3532958 • Letter: R
Question
Requirements
Create a program that interviews the users about their personal information, how many jobs they have and what the income is from each of their jobs. The program should then display back to the user the following items:
The example shown here represents what the user types in green and what the program displays in red.
What is your name? David Freeze
How many jobs do you have? 3
Enter income from job #1: 10000
Enter income from job #2: 30000
Enter income from job #3: 50000
Hello, David Freeze. You have 3 jobs.
The highest paying job pays $50000.
The lowest paying job pays $10000.
The average pay for the 3 jobs entered is $30000.
You can accomplish this program with just one class - a separate tester class is not required.
Explanation / Answer
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class User{
String name;
int numberOfJobs;
static int[] jobSalaries;
int low;
double average;
int high;
public void printStatements(){
System.out.println("Hello "+name+".You have "+this.numberOfJobs+" jobs.");
System.out.println("the highest paying job pays "+this.high);
System.out.println("the lowest paying job pays "+this.low);
System.out.println("the average pay for the"+this.numberOfJobs+"jobs entered is "+this.average);
}
public static void main(String[] args) throws IOException{
User user1=new User();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("What is your name?");
user1.name=br.readLine();
System.out.println("How many Jobs do you have?");
user1.numberOfJobs=Integer.parseInt(br.readLine());
int k=user1.numberOfJobs;
jobSalaries=new int[k];
int sum=0;
for(int i=0;i<k;i++)
{
System.out.println("Enter income for job"+i);
jobSalaries[i]=Integer.parseInt(br.readLine());
sum+=jobSalaries[i];
}
user1.average=sum/k;
int count = 0;
user1.low=jobSalaries[0];
user1.high=jobSalaries[0];
while(count < k)
{
if(jobSalaries[count]< user1.low) {
user1.low = jobSalaries[count];
}
if(jobSalaries[count]> user1.high) {
user1.high = jobSalaries[count];
}
count++;
}
user1.printStatements();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.