Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Requirements Part 1 Create a java program that interviews the users about their

ID: 3767919 • Letter: R

Question

Requirements

Part 1
Create a java 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:

1.       Their name

2.       How many jobs the user has

3.       What the highest paying job pays

4.       What the lowest paying job pays

5.       What the average for all X number of jobs is

The example shown here represents what the user types in bold and what the program displays in italic.

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.

Part 2
Additionally, your program should write an output file to the location and file name of the user's choosing if they would like an output of the information. (So you should first prompt them to see if they want it output to a data file and then prompt for the data file, if applicable.)

I have the code working for part 1 but I cant get part 2 to work with what I already have. Here is my code so far:

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.Scanner;


public class JobCounterFinalProj{

String name;
int numberOfJobs;
static int[] jobSalaries;
int low;
double averageSalary;
int high;
String response;
  
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.averageSalary + ".");

}

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

JobCounterFinalProj user1=new JobCounterFinalProj();
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 {

System.out.println("Please enter income for job #"+ (i+1) + ": ");

jobSalaries[i]=Integer.parseInt(br.readLine());

sum+=jobSalaries[i];

}
user1.averageSalary=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();

}

}

Explanation / Answer

Here is the code for you. If you have any queries, just revert.

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

public class JobCounterFinalProj{
String name;
int numberOfJobs;
static int[] jobSalaries;
int low;
double averageSalary;
int high;
String response;
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.averageSalary + ".");
}
public void writeToFile() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the name of the file to write to: ");
String fileName = br.readLine();
FileOutputStream out = new FileOutputStream(new File(fileName));
  
String content = java.lang.String.format("Hello %s. You have %d jobs. ", this.name, this.numberOfJobs);

byte[] contentInBytes = content.getBytes();
out.write(contentInBytes);
content = String.format("The highest paying job pays $%d. ",this.high);
contentInBytes = content.getBytes();
out.write(contentInBytes);
String.format("The lowest paying job pays $%d. ", this.low);
contentInBytes = content.getBytes();
out.write(contentInBytes);
String.format("The average pay for the %d jobs entered is $%.2f. ", this.numberOfJobs, this.averageSalary);
}
public static void main(String[] args) throws IOException{
JobCounterFinalProj user1=new JobCounterFinalProj();
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("Please enter income for job #"+ (i+1) + ": ");
jobSalaries[i]=Integer.parseInt(br.readLine());
sum+=jobSalaries[i];
}
user1.averageSalary=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();

System.out.print("Do you want the data to be written to file (y/n): ");
char writeToFile = br.readLine().charAt(0);
if(writeToFile == 'y' || writeToFile == 'Y')
{
user1.writeToFile();
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote