User talk:Sakti123

Junit
public class Test1_findAverage extends junit.framework.TestCase { public void testFindAverage1 {   boolean status = false; int input1[] = {10,20,30,40,50}; int input2[] = {100,200,300,400}; String problemMsg= "Method not working for valid inputs"; if( Test1.findAverage(input1) == 30.0 && Test1.findAverage(input2)!=30.0) status = true; assertEquals(problemMsg,true,status); }  public void testFindAverage2 {   boolean status = false; int input1[] = {235,420,350,490,560}; int input2[] = {100,200,300,400}; String problemMsg= "Method not working for valid inputs"; if( Test1.findAverage(input1) == 411.0 && Test1.findAverage(input2)!=411.0) status = true; assertEquals(problemMsg,true,status); }  public void testFindAverage3 {   boolean status = false; int input1[] = {10,20,30,40,50,60,70,80}; int input2[] = {100,200,300,400}; String problemMsg= "Method not working for valid inputs"; if( Test1.findAverage(input1) == 45.0 && Test1.findAverage(input2)!=45.0) status = true; assertEquals(problemMsg,true,status); }  public void testFindAverage4 {   boolean status = false; int input1[] = {15,25,35}; int input2[] = {17,21,37,42}; String problemMsg= "Method not working for valid inputs"; if( Test1.findAverage(input1) == 25.0 && Test1.findAverage(input2)!=25.0) status = true; assertEquals(problemMsg,true,status); }  public void testFindAverage5 {   boolean status = false; int input1[] = {10,20,30,40,-50}; int input2[] = {100,200,300,400}; String problemMsg= "Method not working for invalid inputs"; if( Test1.findAverage(input1) == -1.0 && Test1.findAverage(input2)!=-1.0) status = true; assertEquals(problemMsg,true,status); }  public static void main(String[] args) {   junit.textui.TestRunner.run(new junit.framework.TestSuite(Test1_findAverage.class)); } }

exercise 7
/*6. Items procurement Write a program to accept three arrays, Product Type(“Cosmetic”, “Household”, “Medicinal” ), product quantity and product price and return the total amount required for procurement. Cosmetic items have a tax of 12%, for Household 4% and no tax for medicinal goods.*/

public class Item { public static double calcamount(String type,int quantity,int price) {   double tax=0; if(type.equals("Cosmetic")) tax=12; if(type.equals("Household")) tax=4; if(type.equals("Medicinal")) tax=0; double amount; amount=(100+tax)/100*price*quantity; return amount; } }

public class Batchdistribution { public static int[] arrange(int[] strength,int ref) {   int[] arr=new int[strength.length]; int i=0,j=0; int max=strength[0],min=strength[0],maxindex=getmax(strength),minindex=getmin(strength); if(strength[maxindex]>ref && strength[minindex](ref-min)) {      strength[maxindex]-=(ref-min); strength[minindex]=ref; maxindex=getmax(strength); minindex=getmin(strength); max=strength[maxindex]; min=strength[minindex]; }    else if((max-ref)<(ref-min)) {      strength[maxindex]=ref; strength[minindex]+=(max=ref); maxindex=getmax(strength); minindex=getmin(strength); max=strength[maxindex]; min=strength[minindex]; }    else {      strength[maxindex]=ref; strength[minindex]+=(max=ref); maxindex=getmax(strength); minindex=getmin(strength); max=strength[maxindex]; min=strength[minindex]; }   }    }    if(max==ref) {    for(i=0;iarr[index]) index=i; i++; }     return index; }    public static int getmin(int[] arr) {     int index=0; int i=1; while(i(max[0]*10+max[1]*25+max[2]*50) ) {     System.out.print("Cannot equate"); return f;   } if(tot>=max[2]*50) {     tot=tot-max[2]*50; f[2]=max[2]; if(tot>=max[1]*25) {     tot=tot-max[1]*25; f[1]=max[1]; f[0]=tot/10; }   else {    i=1; while(tot>=25) {      tot=tot-25; i++; }    f[1]=i-1; f[0]=tot/10; }   }    else {       f[2]=tot/50; tot=tot-f[2]*50; f[1]=tot/25; tot=tot-f[1]*25; f[0]=tot/10; }   return f;  } }