6 java questions 1- Savvy Essay Writers | savvyessaywriters.net
6 java questions 1- Savvy Essay Writers | savvyessaywriters.net
1) Book Class
Write a class named Book that has fields to hold the following data:
• Title
• Author
• Year published
• ISBN number
In the Book class, also include
• A mutator method for each field to set the value for the field
• An accessor method for each field to get the value for the field
Write a separate demo program that Utilizies the class by creating three instances of the class.
2) ShoppingCartItem class
Write a class named ShoppingCartItem that has fields to hold the following data:
• Name
• ID number
• Quantity
• Price
In the ShoppingCartItem class, also include
• A constructor that accepts arguments for the name and ID number and assigns them to their respective fields. Initialize the quantity and price fields as well.
• A mutator method for each field to set the value for the field
• An accessor method for each field to get the value for the field
• A method that returns the total price of the item calculated as quantity times price
Write a separate demo program that Utilizies the class bycreating a ShoppingCartItem object and asking the user to enter the data for each of the object’s fields.
The program should display the total price at the end with a label.
3) GroceryItem Class
Write a class named GroceryItem that holds data on an item in a grocery store. Include the following fields:
• description – a String that holds the description of the item
• brand – a String that holds the brand of the item
• inventory – an int that holds the number of units in the inventory
• price – a double that holds the item’s price
Also implement:
• A constructor that accepts an argument for each field and assigns them to their respective fields
• A default constructor that set the description to an empty string ( “†), inventory to 0, and price to 0.0
• A mutator method for each field to set the value for the field
• An accessor method for each field to get the value for the field
Once the class is complete, Write a separate demo program that utilizes the GroceryItem class.
The program should create two GroceryItem objects with the following data:
Description |
Inventory |
Price |
|
Item #1 |
Bananas |
100 |
$0.35 |
Item #2 |
Brisket |
20 |
$45.99 |
Be sure to:
Create one GroceryItem object using the constructor
Create the another GroceryItem object using the default constructor and mutator methods
4) Student Class
Write a class called Student to hold data on a student. Include the following fields:
• name – a string that holds the student’s name
• idNumber – an int that holds the student’s ID number
• major – a string that holds the name of the student’s major
• classification – a string that holds the classification of the student. (Freshman, Sophomore, etc.)
Include the following in the Student class:
• A constructor that accepts arguments for each field and assigns them to their respective fields
• A constructor that accepts only the name and ID number and assigns them to their respective fields. Major and classification should be set to an empty string ( “†)
• A default constructor that assigns empty strings ( “†) to the string fields and 0 to the idNumber field.
• A mutator method for each field to set the value for the field
• An accessor method for each field to get the value for the field
Write a separate demo program that creates three student objects with the following data:
Name |
ID Number |
Major |
Classification |
George Smith |
581375 |
BCIS |
Senior |
Sam Davis |
914685 |
ACCT |
Freshman |
Sarah Brown |
248234 |
FINA |
Junior |
The program should also:
• Utilize each constructor in the class
• Print the data for each student to the screen with labels.
5) Write a java program that use the ArrayList command
The program should initially create a list of 10 countries that you would like to visit. DO NOT include Russia or Peru in your initial list as you will be using them later in the exercise.
Have the program retrieve the 10 names and print them to the screen using println.
The program should then retrieve and print only what is stored at index 4.
The program should then remove what is stored at index 9.
The program should then Add Russia at index 2.
The program should then Replace what is stored at index 7 with Peru.
The program should then print the size of the ArrayList
The program should then print all of the items in the ArrayList and their index
Using println
6) Write a java program that use multiple arrays
This is a simple array program which does not use an “external class & demo program”
If you wish, you may break it down into methods, but that is not required.
a. Set up 4 arrays which hold data about 6 items you want to sell: [make them up]
int[ ] itemnum
int[ ] quantity
double[ ] price
double[ ] sales
b. Set up loops to load the itemnum, quantity and price arrays
c. Set up another loop to calculate values for the sales array. [= price * quantity]
d. Set up another loop to print the item number and sales amount for each transaction
. e. Set up another loop to calculate the total sales of all 6 items
f. print the total sales amount
Savvy Essay Writers
Place your order Now