Write a java program that specifies four parallel one dimensional arrays to store the product name, quantity and cost plus ItemTotal. Each array should be capable of holding a number elements provided by user input. Using a for loop input values for length and width arrays. The entries in the area arrays should be the corresponding values for the product, which is to be used to calculate the costs as follows (thus, itemTotat[i] = quantity [i]* cost [i]) after data has been entered display the following receipt as output:
Sample Run1
Enter the number of products: 2
Enter product 1 name, Qty and Cost: Banana 4 2.65
Enter product 1 name, Qty and Cost: Coke 1 9.18
Output1:
Product Quantity Cost Total
---------- ----------- ------- --------
Banana 4 2.65 10.60
coke 1 9.18 9.18
Sub-Total 19.78
VAT(15%) 2.97
TOTAL N$ 22.75
5. Prompt the user to enter y or n. If the user enters an invalid character, keep re-prompting until a value character is entered. Use a while loop.
6. Redo
for(int a=1; a<=3; a++)
for(int b=2; b<5; b++)
out.print(a+b + " ");
with a do-while loop.
7. Write a method checkeven which receives 3 integer variables and prints YES if all three numbers are even. Otherwise, the method prints NO. ("receives" means that these values will be passed to the method as parameters)
8. Write the statements to read in three numbers and call the checkeven method.
9. Write another version of the checkeven method. This version receives 3 integer variables and returns true if all three numbers are even. Otherwise, the method returns false.
10. Write the statements to read in three numbers and call the new version of the checkeven method. Then print YES if all three numbers were even, or print NO if they were not all even.
I'm quite into games now, so how about we play In or Out! When a given number is even, the team scores so we shall print "In", but if it's not an even number, then we print "Out". Simple, right?
Now let's get this game started.
Input
A line containing an integer.
35Output
A line containing a string.
OutYou have to build 2 classes ExpenseItem, ExpenseLedger Class ExpenseLedger record expenses you make. You record expense by serial number,description,amount. Create a class ExpenseItem with serialnum, description,amount. Provide constructors, toString for this class. Now in ExpenseLedger class create arraylist of ExpenseItem. Provide following methods
void addExpense(description, amount). This method create an expense item and add it to ledger. Int removeSmallExpenses(double amt):This method will find expense items that are smaller or equal to amount amt and remove items from list. Note that multiple items can be smaller than this value and thus each of these should removed. Also this method should return number of items removed. Double totalExpenditure(): This method calculate total expenditure recorded in ledger so far. You can do this by iterating through expenses list and adding all the amounts to find the total expenditure so far. Override toString method so ledger is printed in well formatted way
A line containing an integer.
35Output
A line containing a string.
OutLOOPS&CONDITIONS: Create a program that takes in two numbers and then calculate the sum of all even numbers in between the two numbers. The program should also calculate the products of all the odd numbers between the provided numbers.
Sample run 1:
Enter two numbers: 2 8
Output:
Even numbers: 2 4 6 8
Odd numbers: 3 5 7
Sum of even numbers = 20
Product of odd numbers = 105
Create a program that gets values as CMD args as follows, a person's name, year of birth and gender. The program then prints a message as follows:[HINT: if the person is male then the program uses Mr otherwise use Ms]
Sample 01:
Java Lab01_Task04 John 1999 M
Output
Good Mr John, you are 21 years old
You have to build 2 classes ExpenseItem, ExpenseLedger Class ExpenseLedger record expenses you make. You record expense by serial number,description,amount. Create a class ExpenseItem with serialnum, description,amount. Provide constructors, toString for this class. Now in ExpenseLedger class create arraylist of ExpenseItem. Provide following methods
void addExpense(description, amount). This method create an expense item and add it to ledger. Int removeSmallExpenses(double amt):This method will find expense items that are smaller or equal to amount amt and remove items from list. Note that multiple items can be smaller than this value and thus each of these should removed. Also this method should return number of items removed. Double totalExpenditure(): This method calculate total expenditure recorded in ledger so far. You can do this by iterating through expenses list and adding all the amounts to find the total expenditure so far. Override toString method so ledger is printed in well formatted way
1. Squares
Looping random numbers and manipulating those values are fun, too! Why don't we try one that returns the square of an inputted number repeatedly until the user inputs 0? Let's do this!
Instructions:
Using a do...while() loop, continuously scan for random integers that will be inputted by the user and print out its square, separated in each line.
Once the inputted value is 0, it will still print out its square value but should then terminate the loop afterwards. Use this concept in making your loop condition.
Input
Multiple lines containing an integer.
2
6
Output
Multiple lines containing an integer.
4
36
Sale-Receipt: Write a java program that specifies four parallel one dimensional arrays to store the product name, quantity and cost plus ItemTotal. Each array should be capable of holding a number elements provided by user input. Using a for loop input values for length and width arrays. The entries in the area arrays should be the corresponding values for the product, which is to be used to calculate the costs as follows (thus, itemTotat[i] = quantity [i]* cost [i]) after data has been entered display the following receipt as output:
Sample Run1
Enter the number of products: 2
Enter product 1, Qty and Cost: Banana 4 2.65
Enter product 2, Qty and Cost: Coke 1 9.18
Output1:
Product Quantity Cost Total
---------- ----------- ------- --------
Banana 4 2.65 10.60
coke 1 9.18 9.18
Sub-Total 19.78
VAT(15%) 2.97
TOTAL N$ 22.75