string name;
string DOB;
int hours, status;
int countworkers = 0;
for (int s = 0; s < number; s++)
System.out.print("Enter the amount of worker: ");
int number = sc.nextInt();
System.out.print("name: ");
name = sc.next();
System.out.print("id number: ");
id = sc.next();
System.out.print("hours worked: ");
hour = sc.nextInt();
System.out.print("What is their Status: fulltimeHome, fulltimeonsite parttimehome, parttimeonsite");
status = sc.next();
switch (status) {
case "parttime":
System.out.println("pay " + 3465 ) ;
break;
case "fulltime":
System.out.println("pay " + (hours * 500) ) ;
break;
[NOTE: this isn't the full code, I removed the last two case] My code is using the for-loop. How can I get my program to calculate in total the people that enter they are at home workers (fulltimeHome, parttime home) and those who are working on site (fulltimeonsite, parttimeonsite).
Have 2 variables onSite and homeWorkers for example and in the correct cases add 1 to the correct one.
int onSite = 0, homeWorkers = 0;
and
case "parttime":
System.out.println("pay " + 3465 ) ;
onSite ++;
break;
case "fulltime":
System.out.println("pay " + (hours * 500) ) ;
onSite ++;
break;
case "parttimeHome":
System.out.println("pay " + 3465 ) ;
homeWorkers ++;
break;
case "fulltimeHome":
System.out.println("pay " + (hours * 500) ) ;
homeWorkers ++;
break;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.