# - Write a program to take the input of a number and then check if i...

## Question

- Write a program to take the input of a number and then check if it is a prime number or composite number. Repeat the process for more numbers, till the user wants to.

- Write a program to find the sum of the following series, where x and n are inputs from user. (Without using any pre-defined function and nested loops):
x + x2 + x3 + . . . + xn

- Define a class called Odometer that will be used to track fuel and mileage for an automobile. The class should have instance variables to track the miles driven and the fuel efficiency of the vehicle in miles per gallon. Include a mutator method to reset the odometer to zero miles, a mutator method to set the fuel efficiency, a mutator method that accepts miles driven for a trip and adds it to the odometer’s total, and an accessor method that returns the number of gallons of gasoline that the vehicle has consumed since the odometer was last reset.

Use your class with a test program that creates several trips with different fuel efficiencies. You should decide which variables should be public, if any.

- Write a grading program for a class with the following grading policies:

1. There are three quizzes, each graded on the basis of 10 points.
2. There is one midterm exam, graded on the basis of 100 points.
3. There is one final exam, graded on the basis of 100 points.

The final exam counts for 40% of the grade. The midterm counts for 35% of the grade. The three quizzes together count for a total of 25% of the grade. (Do not forget to convert the quiz scores to percentages before they are averaged in.)
Any grade of 90 or more is an A, any grade of 80 or more (but less than 90) is a B, any grade of 70 or more (but less than 80) is a C, any grade of 60 or more (but less than 70) is a D, and any grade below 60 is an F. The program should read in the student’s scores and output the student’s record, which consists of three quiz scores and two exam scores, as well as the student’s overall numeric score for the entire course and final letter grade.
Define and use a class for the student record. The class should have instance variables for the quizzes, midterm, final, overall numeric score for the course, and final letter grade. The overall numeric score is a number in the range 0 to 100, which represents the weighted average of the student’s work. The class should have methods to compute the overall numeric grade and the final letter grade. These last methods should be void methods that set the appropriate instance variables. Your class should have a reasonable set of accessor and mutator methods, an equals method, and a toString method, whether or not your program uses them. You may add other methods if you wish.

- Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have four constructor methods: one for each instance variable (assume zero degrees if no value is specified and Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument constructor (set to zero degrees Celsius). Include the following: (1) two accessor methods to return the temperature—one to return the degrees Celsius, the other to return the degrees Fahrenheit—use the following formulas to write the two methods, and round to the nearest tenth of a degree:

DegreesC=5(degreesF−32)/9DegreesF=(9(degreesC)/5+32);
DegreesC=5(degreesF−32)/9 DegreesF=(9(degreesC)/5+32);
(2) three mutator methods: one to set the value, one to set the scale (F or C), and one to set both;
(3) three comparison methods: an equals method to test whether two temperatures are equal, one method to test whether one temperature is greater than another, and one method to test whether one temperature is less than another (note that a Celsius temperature can be equal to a Fahrenheit temperature as indicated by the above formulas); and (4) a suitable toString method. Then write a driver program (or programs) that tests all the methods. Be sure to use each of the constructors, to include at least one true and one false case for each of the comparison methods, and to test at least the following temperature equalities: 0.0 degrees C = 32.0 degrees F, –40.0 degrees C = –
40.0 degrees F, and 100.0 degrees C = 212.0 degrees F.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/*
* Odometer class
*/
public class Odometer {

private double fuelEfficiency;
private double milesDriven;

public Odometer(double fuelEfficiency) {
this.setFuelEfficiency(fuelEfficiency);
this.resetMilesDriven();
}

public void setFuelEfficiency(double fuelEfficiency) {
this.fuelEfficiency = fuelEfficiency;
}

public double getFuelEfficiency() {
return this.fuelEfficiency;
}

public void resetMilesDriven() {
this.milesDriven = 0.0;
}

this.milesDriven += miles;
}

public double getMilesDriven(double miles) {
return this.milesDriven;
}

public double getGasConsumed() {
double gasConsumed = this.milesDriven / this.fuelEfficiency;
return Math.round(100 * gasConsumed) / 100.0;
}

@Override
public String toString() {
result += "Fuel efficiency: " + this.fuelEfficiency + " mpg\n";
result += "Miles driven: " + this.milesDriven + " miles\n";
result += "Gas consumed: " + getGasConsumed() + " gallons\n";
return result;
}
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

\$45.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

• 1
• 2
• 3
Live Chats