Question

In: Computer Science

Assignment #2*: Build A Report Purpose: Exercise, use, Inputs, Outputs, and perform conditional evaluation Requirements: (Multiple...

Assignment #2*: Build A Report Purpose: Exercise, use, Inputs, Outputs, and perform conditional evaluation Requirements: (Multiple classes/Multiple types of input) • Input: Report Owner’s full name and 7 numbers (at least one double and one integer) o The owner’s name cannot contain any special characters, blank spaces, or numbers • You must use an if statement and at least one switch statement in your program • You are not allowed to have static variables or methods in any class except for the class with the main method. • You have to have at least 2 classes • You are not allowed to use ArrayLists or Vectors, only primitive arrays or string arrays if you want. Application Operation: 1.) Input, via a question in the console, the report owner’s first name as a string and build the last name via input, one character at a time. a. Check, conditionally, to make sure the first name and last name don’t contain any numeric characters, numbers between 0 – 9. If it does you must remove it. The names can not contain any white space either or special characters. 2.) Input report name via a request from the console. 3.) Input, and display, the total of the numeric input after each input is entered. Average the numeric input, indicate lowest numeric input value and the highest numeric input value for the previous numeric inputs, before the next numeric input is asked for. (Example given in class) 4.) Have a program exit input, condition, value available (i.e. if you type -1 the program exits) 5.) Create and display a final report that should have the report name, owner and the following: Numeric output should appear as a table with the following columns: (columns should be underlined) a. Input Number b. Highest Number c. Lowest Number d. Total (by the row) e. Average Number 6.) At the end of the report you must have a grand total for the numeric entries

Solutions

Expert Solution

import java.util.Scanner;

// Defines class Test

class Test

{

// To store first, last, report name

String fName, lName, reportName;

// To store total, average, height and lowest numbers

double total, average, highest, lowest;

// Scanner class object declared

Scanner sc;

// Default constructor to initialize data members

Test()

{

fName = lName = reportName = "";

highest = lowest = total = average = 0.0;

// Scanner class object created

sc = new Scanner(System.in);

}// End of default constructor

// Method to accept name

void acceptName(String message, int type)

{

// To store valid name

String validName = "";

// Displays message

System.out.print("\n Enter your " + message);

// Accepts name

String name = sc.next();

// Loops till end of the string

for(int c = 0; c < name.length(); c++)

{

// Extracts a character at c index position from string

char ch = name.charAt(c);

// Checks if the current character is a digit

if(Character.isDigit(ch))

;// Do nothing

// Otherwise add the character to valid name

else

validName += ch;

}// End of for loop

// Checks if the second parameter type is 1 (first name)

if(type == 1)

fName = validName;

// Checks if the second parameter type is 2 (last name)

else if(type == 2)

lName = validName;

// Otherwise the second parameter type is 3 (report name)

else

reportName = validName;

}// End of method

// Method to accept number

void acceptNumbers()

{

// Counter for number of numbers entered

int counter = 0;

// Loops till user enters -1

do

{

// Accepts a number

System.out.print("\n Enter a number (-1 to stop): ");

int no = sc.nextInt();

// Checks if user entered -1 then come out of loop

if(no == -1)

break;

// Otherwise

else

{

// Increase the counter by one

counter++;

// Checks if counter is 1

if(counter == 1)

// Assigns the number to both highest and lowest

highest = lowest = no;

// Otherwise not the first number

// Checks if number is greater than the earlier

// highest number

else if(no > highest)

// Assigns the number as the highest number

highest = no;

// Checks if number is less than the earlier

// lowest number

else if(no < lowest)

// Assigns the number as the lowest number

lowest = no;

// Calculates total and average

total += no;

average = total / counter;

// Displays message

System.out.print("\n Number: " + no +

"\n Highest: " + highest +

"\n Lowest: " + lowest +

"\n Total: " + total +

"\n Average: " + average);

}// End of else

}while(true); // End of do - while loop

}// End of method

}// End of class

// Driver class definition

public class ValidateTest

{

// main method definition

public static void main(String st[])

{

// Creates an object of class Test

Test t = new Test();

// Calls the method to accept first name

t.acceptName("first name.", 1);

// Calls the method to accept last name

t.acceptName("last name.", 2);

// Calls the method to accept report name

t.acceptName("report name.", 3);

// Displays names

System.out.println("\n First Name: " + t.fName +

"\n Last Name: " + t.lName +

"\n Report Name: " + t.reportName);

// Calls the method to accept numbers

t.acceptNumbers();

}// End of main method

}// End of driver class

Sample Output:


Enter your first name.P12yari

Enter your last name.Mo12han

Enter your report name.Number

First Name: Pyari

Last Name: Mohan

Report Name: Number

Enter a number (-1 to stop): 12

Number: 12
Highest: 12
Lowest: 12
Total: 12.0
Average: 12.0
Enter a number (-1 to stop): 10

Number: 10
Highest: 12
Lowest: 10
Total: 22.0
Average: 11.0
Enter a number (-1 to stop): 6

Number: 6
Highest: 12
Lowest: 6
Total: 28.0
Average: 9.333333333333334
Enter a number (-1 to stop): -1


Related Solutions

Assignment Requirements: 1. Find a workout or create a workout and perform it. If you use...
Assignment Requirements: 1. Find a workout or create a workout and perform it. If you use an online workout/video please reference it so I know what you've done. If you create one yourself, make sure to include your written workout in the assignment. 2. Write about each component/part of the workout and how it related to the health-related components of physical fitness. Answer in detail.
Assignment #2: Individual Macronutrient Requirements and Diet Report Required to Submit: Previous assignment #1 and …....
Assignment #2: Individual Macronutrient Requirements and Diet Report Required to Submit: Previous assignment #1 and …. Your Individual Macronutrient Requirements for: Total kcals, Protein, Fat, Carbohydrate & Fiber Completed Diet Report Complete the Report Questions Completing the Diet Report Once you have recorded your 3-day diet, . You can also access the website in the Diet Project Resources module in Canvas. Instructions on how to generate the Cronometer nutrition analysis report can be found in the Diet Project Resources module....
Colander – Chapter 2 Discuss the following: (please use graphs when relevant) Efficiency Inputs Outputs Increasing...
Colander – Chapter 2 Discuss the following: (please use graphs when relevant) Efficiency Inputs Outputs Increasing and constant opportunity costs Production possibilities curve / frontier (PPC / PPF) Specialization Laissez-faire Absolute advantage Comparative advantage Globalization
The purpose of this assignment is to use prefixes, suffixes, word roots, and combining vowels to build and define medical terms
  Purpose: The purpose of this assignment is to use prefixes, suffixes, word roots, and combining vowels to build and define medical terms; to use basic medical language in written communication; and to interpret the meaning of medical terms used in written and verbal communication. Action Items1. Look through for English journal articles on human anatomy. Choose an article.2. Select 5 medical terms from the article.3. In the first column list the medical term.4. In the second column, list any...
Chapter 2 is using the EXCEL functions FV, PV, NPV, PMT, NPER, RATE & SUM. Explain in plain English in a clear and detail way how you can use these functions. How many inputs you need for each of these outputs?
Chapter 2 is using the EXCEL functions FV, PV, NPV, PMT, NPER, RATE & SUM. Explain in plain English in a clear and detail way how you can use these functions. How many inputs you need for each of these outputs? Are all inputs required? Why not? Use the excel help in order to understand these Formulas. Do not copy and paste. This question has seven parts, identify each part with a letter from the beginning of the alphabet, as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT