Assignment 6
Assignment 6
Assignment 6
Q1:
import java.util.Scanner;
do { number = s.nextInt();
total += number;
count++;
if(number > 0){
positive++;
}
else if(number < 0){
negative++;
}
}
while(number != 0);
}
Q2:
Algorithm:
Start
Enter product number
Enter quantity sold
Total price 1= price 1of number *quantity sold
Total price 2= price 2of number *quantity sold
Total price 3= price 3of number *quantity sold
Total price 4= price 4of number *quantity sold
Total price 5= price 5of number *quantity sold
Code;
import java.util.Scanner;
while (true) {
System.out.println("price of product 1 is RM2.98");
System.out.println("price of product 2 is RM4.5");
System.out.println("price of product 3 is RM9.98");
System.out.println("price of product 4 is RM4.49");
System.out.println("price of product 5 is RM6.87");
System.out.println("-9999 out of programm");
System.out.println("Enter product number");
int p= s.nextInt();
if(p == -9999)
break;}
System.out.println("Enter quantity sold");
int q = s.nextInt();
switch('p') {
case 1:
totalprice+=2.98*q;
break;
case 2:
totalprice+=4.50*q;
break;
case 3:
totalprice+=9.98*q;
break;
case 4:
totalprice+=4.49*q;
break;
case 5:
totalprice+=6.87*q;
break;}
System.out.println("The total retail value of all
products sold: $"+totalprice);