Your mission is to design and (at least partially) implement a Java program to h
ID: 3545404 • Letter: Y
Question
Your mission is to design and (at least partially) implement a Java program to help students in
early elementary school practice their arithmetic skills. The student will enter his or her grade
level (1, 2 or 3) and the program will respond with a menu something like the following (will
vary by grade level):
Which kind of problem do you want to practice?
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. I want to try them all
Please enter your choice (1, 2, 3, 4 or 5):
The student enters his or her choice, and the program responds by presenting the user with the
specified arithmetic problems appropriate to the student's grade level:
? 1st graders get 1-digit numbers only
? 2nd graders can get 1 or 2-digit numbers
? 3rd graders get 1, 2 or 3-digit numbers
If the student chooses the last option, the program should present a random assortment of all 4
types of problems.
The problems are presented one at a time, in groups of 10; after the tenth problem, the student is
given an opportunity to try another kind of problem or quit the program.
When a student has completed 10 problems, s/he should be given feedback about how many
answers were right or wrong in that set, and also a grand total of right and wrong answers for all
sets completed so far during this session.
Explanation / Answer
/*This Java program performs basic arithmetic operations
*addition, subtraction, multiplication and division
*/
public class BasicArithmeticDemo
{
public static void main(String[] args)
{
int number1 = 10;
int number2 = 5;
//calculating number1 + number2;
int sum = number1 + number2;
//calculating number1 - number2;
int difference = number1 - number2;
//calculating number1 * number2;
int product = number1 * number2;
//calculating number1 / number2;
int quot = number1 / number2;
//calculating number1 % number2;
int rem = number1 % number2;
//Displaying the values
System.out.println("number1 : "+number1);
System.out.println("number2 : "+number2);
System.out.println("sum : "+sum);
System.out.println("difference : "+difference);
System.out.println("product : "+product);
System.out.println("quot : "+quot);
System.out.println("rem : "+rem);
}
}
package test;
class Student {
int id;
String name;
int age;
String department;
String course;
String grade;
double gpa;
Student(int id, String name, int age, String department, String course, String grade, double gpa) {
this.id = id;
this.name = name;
this.age = age;
this.department = department;
this.course = course;
this.grade = grade;
this.gpa = gpa;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getDepartment() {
return department;
}
public String getCourse() {
return course;
}
public String getGrade() {
return grade;
}
public double getGpa() {
return gpa;
}
public String toString() {
return getId() + " " + getName() + " " + getAge() + " " + getDepartment() + " " + getCourse() + " " + getGpa();
}
}
package test;
import java.util.*;
public class CalculateGPA {
ArrayList<Student> list = new ArrayList();
public static void main(String[] args) {
new CalculateGPA();
}
public CalculateGPA() {
Scanner input = new Scanner(System.in);
double gpa = 0;
for (int i = 0; i < 5; i++) {
System.out.print("Enter id: ");
int id = input.nextInt();
System.out.print("Enter Name: ");
String name = input.next();
System.out.print("Enter Age: ");
int age = input.nextInt();
System.out.print("Enter Department: ");
String department = input.next();
System.out.print("Enter course: ");
String course = input.next();
System.out.print("Enter grade: ");
String grade = input.next();
if (grade.equals("A") || grade.equals("a")) {
gpa = 4;
} else if (grade.equals("B") || grade.equals("b")) {
gpa = 3;
} else if (grade.equals("C") || grade.equals("c")) {
gpa = 2;
} else if (grade.equals("D") || grade.equals("d")) {
gpa = 1;
} else if (grade.equals("F") || grade.equals("f")) {
gpa = 0;
}
list.add(new Student(id, name, age, department, course, grade, gpa));
}
for (Student s : list) {
System.out.println(s.toString());
}
Student s = searchStudent(1);
System.out.println(s.toString());
}
public Student searchStudent(int id) {
for (Student student : list) {
if (student.getId() == id) {
return student;
}
}
return null; // not found
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.