import java.util.*; public class Quiz_4_28_2015 { //Data Fields private String n
ID: 656094 • Letter: I
Question
import java.util.*;
public class Quiz_4_28_2015 {
//Data Fields
private String name = "Unknown";
private String course = "TBD";
private String school = "TBD";
private Date dateCreated;
//************************************************
//1. no-argument Constructor:
//Assign your name to name, course, and school to name,
// course, and school
//Assign the system's date to dateCreated
//***********************************************
public Quiz_4_28_2015 (){
this.name = name;
this.course= course;
school= name;
dateCreated = new Date();
}
//************************************************
//2. Constructor:
//Assigns the received arguments to name, course,
//and school. Also, gets the system's date and
//assign it to dateCreated
//***********************************************
public Quiz_4_28_2015 (String school, String name, String course){
dateCreated = new Date();
System.out.println ("2: Constructor To be implemented"); //remove this line when completed
}
//************************************************
//3. celsius:
//
//The method celsius accepts a single argument of a fahrenheit temperature.
//It computes and returns the equivalent celsius temperature, using the formula:
//celsius = 5/9 (F - 32)
//***********************************************
public double celsius (int fahrenheit){
double celsius = ((5/9) * (fahrenheit - 32));
return celsius;
}
//**********************************************************
//4. countOfLetters: Write a method that accepts a string argument.
// counts the number of all letters in the string.
// For example, if we pass "CS 1301ab $%^&" the methord shoule return
// 4.
//**********************************************************
public int countOfLetters(String str){
System.out.println (" 4: countOfLetters: To be implemented"); //remove this line when completed
return -4; //update this statement
}
//************************************************
//5. calculateSales:
//An online retailer sells six products whose retail prices are as follows:
//Product 1, $3.98; product 2, $5.50; product 3, $10.98; product 4, $8.50;
//product 5, $7.87, and product 6, 99.9.
//
//The method calculateSales accepts two arguments for product number
//and quantity sold.
//Use a swicth statement to determine and return the retail price for the product.
//For example, if method receives 2 and 10, it should return 55.00.
//The method return 0 for invalid product number.
//***********************************************
public double calculateSales (int product, int quantity){
double amount;
switch(product){
case 1: amount = 3.98;
break;
case 2: amount = 5.50;
break;
case 3: amount = 10.98;
break;
case 4: amount = 8.50;
break;
case 5: amount = 7.87;
break;
case 6: amount = 9.99;
break;
default: amount = 0;
}
return amount * quantity;
}
//**********************************************************
//6. printList: Write a method that accepts an ArrayList
// of type Integer and displays its values.
// For example, if the list has 2, 5, and 7, it should
// display 2, 5, and 7.
//**********************************************************
public void printList (ArrayList <Integer> list) {
System.out.println ("6: printList: To be implemented"); //remove this line when completed
}
//**********************************************************
//7. oddPartialAverage: Write a method that computes the average all odd values
// from m to n (inclusive) with the exceptions of values that
// are divisible by k. For example, if m is 2, n is 17, and k is 5,
// the method will return 9.4 (3 + 7 + 9 + 11, 17) / 5
//**********************************************************
public double oddPartialAverage(int m, int n, int k){
System.out.println (" 7: oddPartialAverage: To be implemented"); //remove this
return -7; //update
}
//************************************************
//8. reverseDigits:
//
//The method reverseDigits accepts a single argument of type integer.
//The method takes an integer value and returns the number with its digits
//reversed. For example, given the number 7631, the method should return 1367.
//***********************************************
public int reverseDigits(int number){
int digits=0;
while (number>0){
digits = digits*10+number%10;
number/=10;
}
return digits;
}
//***********************************************
//toString:
//***********************************************
public String toString () {
String result;
result = " Name: " + name +
" Course: " + course +
" School: " + school +
" Date: " + dateCreated;
return result;
}
}
Explanation / Answer
for part 3 of the question:
for part 4 of the question:
for part 8:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.