hey guys so i'm trying to get a lot better at coding over the summer so my cs2 class will be a breeze in the fall so i'm brushing up on my arrays. here is the problem i did i feel like the code is sloppy and it could be improved so any feedback would be wonderful.
Use a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9% of $5000, or a total of $650. Write an application (using an array of counters)that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson’s salary is truncated to an integer amount): a) $200–299 b) $300–399 c) $400–499 d) $500–599 e) $600–699 f) $700–799 g) $800–899 h) $900–999 i) $1000 and over
import java.util.*;
public class TestCommision {
public static void main(String[] args){
int[] salary=new int[9];
Scanner input= new Scanner(System.in);
boolean flag = true;
int count=0;
while(count!=-1)
{
System.out.println("what was this employees gross pay (input -1 to stop)");
int grosspay=input.nextInt();
if(grosspay==-1)
count=-1;
Commision i=new Commision(grosspay);
if(i.getCommission()>200 && i.getCommission()<299)
salary[0]++;
else if(i.getCommission()>300 && i.getCommission()<399)
salary[1]++;
else if(i.getCommission()>400 && i.getCommission()<499)
salary[2]++;
else if(i.getCommission()>500 && i.getCommission()<599)
salary[3]++;
else if(i.getCommission()>600 && i.getCommission()<699)
salary[4]++;
else if(i.getCommission()>700 && i.getCommission()<799)
salary[5]++;
else if(i.getCommission()>800 && i.getCommission()<899)
salary[6]++;
else if(i.getCommission()>900 && i.getCommission()<999)
salary[7]++;
if(i.getCommission()>=1000)
salary[8]++;
}
System.out.println("there were " + salary[0] + " employees who made between 200-299 dollars this week" );
System.out.println("there were " + salary[1] + " employees who made between 300-399 dollars this week" );
System.out.println("there were " + salary[2] + " employees who made between 400-499 dollars this week" );
System.out.println("there were " + salary[3] + " employees who made between 500-599 dollars this week" );
System.out.println("there were " + salary[4] + " employees who made between 600-699 dollars this week" );
System.out.println("there were " + salary[5] + " employees who made between 700-799 dollars this week" );
System.out.println("there were " + salary[6] + " employees who made between 800-899 dollars this week" );
System.out.println("there were " + salary[7] + " employees who made between 900-999 dollars this week" );
System.out.println("there were " + salary[8] + " employees who at least made a thousand dollars this week" );
}
}
public class Commision {
private int GrossPay,Commision;
public Commision( int grosspay)
{
setGrossPay(grosspay);
}
public void setGrossPay(int grosspay)
{
GrossPay=grosspay;
}
public int getCommission()
{
Commision=(int) (200+(GrossPay * .09));
return Commision;
}
}
Aucun commentaire:
Enregistrer un commentaire