Question

In: Computer Science

Java program Test Scores? Design a TestScore class that has three integer fields, each holding a...

Java program Test Scores?

Design a TestScore class that has three integer fields, each holding a test score. The
class should have accessor and mutator methods for the test score fields and a method that
returns the average of the test scores as a double.

Test the TestScore class by writing a separate program that creates an instance of the class. The program should ask the user to enter three test scores, which should be stored in the TestScore object. The program should then print the average of the scores.

Solutions

Expert Solution

CODE FOR TestScore CLASS:(TestScore.java)

class TestScore
{
public int test_score1;
public int test_score2;
public int test_score3;
public TestScore(int t1,int t2,int t3)
{
test_score1 = t1;
test_score2 = t2;
test_score3 = t3;
}
public int getScore1()
{
return test_score1;
}
public void setScore1(int test_score1)
{
this.test_score1 = test_score1;
}
public int getScore2()
{
return test_score2;
}
public void setScore2(int test_score2)
{
this.test_score2 = test_score2;
}
public int getscore3()
{
return test_score3;
}
public void setScore3(int test_score3)
{
this.test_score3 = test_score3;
}
public double average()
{
double avg = (test_score1+test_score2+test_score3)/3;
return avg;
}
}

CODE FOR AvgScore CLASS:(AvgScore.java)

import java.util.Scanner;
public class AvgScore
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter three test scores: ");
int score1 = sc.nextInt();
int score2 = sc.nextInt();
int score3 = sc.nextInt();
TestScore cs = new TestScore(score1,score2,score3);
double avrg = cs.average();
System.out.println("The average of three test scores is:"+avrg);
}
}

OUTPUT:


Related Solutions

(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone number (all Strings) –Write a constructor that takes all the required information. –Write a constructor that only takes the name of the person and uses this to call the first constructor you wrote. –Implement the accessor and mutator methods. Make them final so subclasses cannot override them –Implement the toString() method •Design a class named Customer, which extends the Person class. It should have...
Write a java program using the following information Design a LandTract class that has two fields...
Write a java program using the following information Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and...
In java, (include javadoc comments for each method) design a class named Contacts that has fields...
In java, (include javadoc comments for each method) design a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contacts objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to...
In java, design a class named Motorcycle that has the following fields: • year – The...
In java, design a class named Motorcycle that has the following fields: • year – The year field is an int that holds the motorcycle’s year • make – The make field references a String object that holds the make of the motorcycle. • speed – The speed field is an int that holds the motorcycle’s current speed The class should have the following constructor and other methods: • Constructor – the constructor should accept the motorcycle’s year and make...
/*Design and code and test a class MaxMin that has the following properties * two integer...
/*Design and code and test a class MaxMin that has the following properties * two integer member variables, min and max where min is smaller or equal than max at all times * A default constructor that sets both min and max to 0 * A constructor that accepts one integer and sets both min and max to that integer * A constructor that accepts two integers and sets min the smallest and max the largest * * Setters and...
Design a class named Person with fields for holding a person's name, address, and telephone number(all...
Design a class named Person with fields for holding a person's name, address, and telephone number(all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes these...
Design a class named Person with fields for holding a person's name, address, and telephone number(all...
Design a class named Person with fields for holding a person's name, address, and telephone number(all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes these...
a) Design a Java Class which represents a Retail Item. It is to have the following fields
 a) Design a Java Class which represents a Retail Item. It is to have the following fields Item Name Item Serial No Item Unit Price Item Stock Level Item Reorder Level It is to have at least the following methods an Observer, Mutator and a Display method for each field. It is also to have a buy and a restock method and a method to issue a warning if the stock level goes below the re-order level. b) Extend the Retail Item class of part a) above...
a) Design a Java Class which represents a Retail Item. It is to have the following fields
 a) Design a Java Class which represents a Retail Item. It is to have the following fields  Item Name  Item Serial No  Item Unit Price  Item Stock Level  Item Reorder Level  It is to have at least the following methods an Observer, Mutator and a Display method for each field. It is also to have a buy and a restock method and a method to issue a warning if the stock level goes below the re-order level.    b) Extend...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT