Concept explainers
Write a program in a class FlowerCounter that computes the cost of flowers sold at a flower stand. Five kinds of flowers—petunia, pansy, rose, violet, and carnation—are stocked and cost, respectively, 50¢ 75¢, $1.50, 50¢, and 80¢ per flower. Create an array of strings that holds the names of these flowers. Create another array that holds the cost of each corresponding flower. Your program should read the name of a flower and the quantity desired by a customer. Locate the flower in the name array and use that index to find the cost per stem in the cost array. Compute and print the total cost of the sale.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Problem Solving with C++ (9th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
C How to Program (8th Edition)
Absolute Java (6th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- 1. write a static method that receive as parameter an array of type student and print the names of all students excepted to graduate. The student is expected to graduate if he/she in year 4 and GPA >2. 2. Write a java program that: a. Asks the user to enter the number of the Student, then the data of each Student and store then inside an array of type Student. b. Ask the user to read a value d of type double then displays the name of all the Student who have GPA greater than the value d. c. Call the above method and print the name of student who excepted to graduate.arrow_forwardWrite a program in a class NumberAboveAverage that counts the number of days that the temperature is above average. Read ten temperatures from the keyboard and place them in an array. Compute the average temperature and then count and display the number of days on which the temperature was above average.arrow_forwardWrite a RainFall class that stores the total rainfall for each of 12 months into an array of double s. The program should have methods that return the following: • the total rainfall for the year • the average monthly rainfall • the month with the most rain • the month with the least rain • Test the RainFall class by writing a tester class, RainFallDemo , to produce the outputs similar to the sample execution below. For the rainfall values, you must get them from the user’s input as double values in the tester class. For the class RainFall you must write standard Java Documentation for the whole class on the top, and for every method. Input Validation: Do not accept negative numbers for monthly rainfall figures. If a value is negative, ask the user to re-enter the input.arrow_forward
- Write a program in Java that reads integers, one per line, and displays their sum. Also, display all the numbers read, each with an annotation giving its percentage contribution to the sum. Use a method that takes the entire array as one argument and returns the sum of the numbers in the array. (Hint: Ask the user for the number of integers to be entered, create an array of that length, and then fill the array with the integers read.arrow_forwardJAVA PROGRAM Write a program that asks the user to input two integers a and b. Then create an array that has all integer from a to b. Print out the array. (Don’t forget to consider the situation of a=b, a<b, and a>b.) Example 1: Input two numbers: 6 2 Array is [6, 5, 4, 3, 2] Example 2: Input two numbers: 4 8 Array is [4, 5, 6, 7, 8] Pass the above array as a parameter to a method called average and return the average and print it out in the main method. (Do not use Math library to get the average.)arrow_forwardFOR JAVA Write a method that takes an integer array, prints the elements that are divisible by 3 and returns the sum of these elements. Write a method that takes an integer array and returns the difference between the sum of even indexed elements and the sum of odd indexed elements in that array. Write a method that takes a String array and an integer as parameters and prints the Strings in the array whose length is greater than the second parameter. Write a method that takes two integer arrays, and returns a new array by taking the intersection of the two arrays.arrow_forward
- Write a program that declares an array of 15 integers and reads the values from the user. Make sure that the user doesn’t enter a value greater than 10 (if the user enters a value not in the allowed range, discard that value and read another to put into the array). Now tell the number that occur maximum number of times in the array. For example for the following 7 has maximum occurrence. 4,7,3,3,2,7,1,5,7,9,9,9,7,8,10 Use both linear and binary search.arrow_forwardWrite a Java program named Findletter that asks the user to enter 10 letters and store them in an array. Then it should ask the user to enter a letter (char value) to search for it. Then, if the entered letter is found, the program should display the message "The letter is in the array", otherwise it should display the message "The letter is not in the array".arrow_forwardSuppose you are given a `Employee` class with instance variables `name`, `age`, `department, and salary. You are also given a static variable "total Employees and a static variable `totalSalary`, which respectively keep track of the total number of employees and the total salary of all employees. Using this class, write a Java program that does the following: 1. Create an array of size 3 to store Employee objects. 2. Initialize the array with the following Employee` objects: • Name: Alice, Age: 25, Department: HR, Salary: 50,000 Name: Bob, Age: 35, Department: Marketing, Salary: 60,000 Name: Charlie, Age: 30, Department: Sales, Salary: 55,000 3. Modify the age of the first employee in the array to 26. 4. Modify the salary of the second employee in the array to 65,000. 5. Print out the total number of employees and the average salary of all employees. 6. Use the static method `findEmployeeByName to find the `Employee` object with the name "Alice", and print out the…arrow_forward
- (a)Implement all the classes. The formula for calculating salary for each class is shown below: For the Employee class, salary = basic salary + allowance For the Manager class , salary = basic salary + allowance + travel claims For the Clerk class , salary = basic salary + allowance + overtime pay,where overtime pay = overtime hours x overtime rate. Set overtime rate as RM3.50. Write a client program that creates an array named empArray that stores an object of an Employee,a Manager and a Clerk.In your program, include a method called printElements() that takes an array as parameter and prints the type of employee, the object’s data field values (by invoking thetoString() method) and the monthly salary.arrow_forwardWrite a program called Range_array.java that has a method with one integer array and two integers position1 and position2 as parameters, where 0<=position1<=position2<=a.length-1. The method should construct and return an array that is identical to the given array, but with the values in position1 through position2 deleted. The output should look exactly like what is pictured below please. The code must be editable, and all variables defined within please.arrow_forwardWrite a program called Words that: prints your name followed by three asterisks; reads the words in a text file into a String array, where each array entry contains a word; prints the number of words in the file; counts and prints the number of five-letter words; prints all of the five-letter words starting with a vowel (that is, 'a', 'e', 'i', 'o', or 'u'); finds and prints the alphabetically first five-letter word and the alphabetically last five-letter word. it was the best of times it was the worst of timesit was the age of wisdom it was the age of foolishnessit was the epoch of belief it was the epoch of incredulityit was the season of light it was the season of darknessit was the spring of hope it was the winter of despairwe had everything before us we had nothing before uswe were all going direct to heaven we were all going directthe other wayin short the period was so far like the presentperiod that some of its noisiest authorities insisted on itsbeing received for good or…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning