import static java.lang.System.*; public class Social { private String socialNum
ID: 3632767 • Letter: I
Question
import static java.lang.System.*;public class Social
{
private String socialNum;
//Hold the total of the digits
private int sum;
private int one, two, three;
public Social()
{socialNum = " ";
sum = 0;
}
public Social(String soc)
{setWord(soc);
}
public void setWord(String w)
{ socialNum = w;
}
//Calculates the total of the numbers in the credit card:
//Example socialNum = 12-12-12 results in sum = 36
public void chopAndAdd()
{
String sub = socialNum;
> two =
three =
sum = one + two + three;
}
//Already complete. Returns the outcome of chopAndAdd()
public String toString()
{
return "SS# " + socialNum + " has a total of " + sum + " ";
}
}
Chop up a Social Security number, add up all the numeric pieces, and output the total. 12-12-12 would result in an output of 36.
Explanation / Answer
public void setWord(String w)
//Calculates the total of the numbers in the credit card:
//Example socialNum = 12-12-12 results in sum = 36
}
//Already complete. Returns the outcome of chopAndAdd()
}
}
SS# 12-12-12 has a total of 36
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.