Class <em>t</em><em>e</em><em>m</em><em>p</em><em>l</em><em>a</em><em>t</em><em>e</em><em>s</em> allow you to create one version of a class, without having to replicate code to handle multiple data types.
Answer:
What was the actual the question? I am confused.
Explanation:
Answer:
It can take a negative input
Explanation:
When you declare a variable in Java and you get your input via Scanner library; the Scanner library will accept the input irrespective of whether it's negative or not.
Take for instance, the following segment
<em>Scanner input = new Scanner(System.in);</em>
<em>int userinput = input.nextInt()</em>
<em />
Irrespective of whether userinput is negative or positive, it'll accept it.
lst=([])
def avgGPA(lst1):
total = 0
count = 0
for x in lst:
if type(x) == int:
total += x
count += 1
return total/count
def GPAcalc(grade, weighted):
grade = grade.lower()
dictionary = {"a": 4, "b": 3, "c": 2, "d": 1, "f": 0}
if weighted == 1 and grade in dictionary:
lst.append(dictionary[grade]+1)
return "Your GPA score is: " + str(dictionary[grade] + 1)
elif weighted == 0 and grade in dictionary:
lst.append(dictionary[grade])
return "Your GPA score is: " + str(dictionary[grade])
else:
lst.append("Invalid")
return "Invalid"
classes = int(input("How many Classes are you taking? "))
i = 0
while i < classes:
print(GPAcalc(input("Enter your Letter Grade: "), int(input("Is it weighted? (1 = yes) "))))
i += 1
print("Your weighted GPA is a "+str(avgGPA(lst)))
If you need me to change any code, I'll do my best. I hope this helps!