Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Write a program to accept marks in 4 subjects, find the average and display the grades. < 50 – F, < 60 – A, < 70 –B, < 85 – C, > 85 –S
Design and implement a class called DateWriter that has three instance variables:
a string for month, an integer for day, and an integer for year. The class should has
a constructor to accept and initialize the values of the instance variables, and a
getter and a setter method for each instance variable. Include the following
methods:
1) A method called monthInteger that has no parameters and returns an integer
value represents the month.
2) A method called monthString that has a parameter monthNumber of type
integer and returns a string represents the month.
3) A method called setDate that has three integer parameters: newMonth,
newDay, and newYear. The method should set the three instance variables,
even though the month instance variable is of type string, you have to
convert the month integer value to a string with a call to method
monthString.
4) A method called makeItNewYear that has no parameters and sets the month
instance variable to “January” and the day instance variable to 1. It doesn’t
change the value of the year instance variable.
5) A method called yellIfNewYear that has no parameters and outputs the
string “Hurrah!” if the month instance variable has the value “January” and
the day instance variable has the value 1. Otherwise, it outputs the string
“Not new year’s day.”
6) A method called getNextYear that has no parameters and returns an integer
value represents the next year.
7) A method called fractionDone that has a parameter targetDay of type
integer (for a day of a month) and returns a value of type double. The value
returned is the value of the day instance variable divided by the integer
parameter targetDay. (so it returns the fraction of the time passed so far this
month where the goal is reaching the targetDay).
Note: Do floating-point division not integer division, and Check the value
of the targetDay if it’s not a valid day of a month, then print an error
message to the standard output and return zero to the caller.
8) A method called advanceYear that has one parameter of type integer. The
method advanceYear increases the value of the year instance variable by
the amount of this one parameter.

Finally, create a driver (main or client) class called DateDemo, whose main
method instantiates several (at least 3 DateWriter objects) and uses all methods
you created. Prompt the user to enter the data.
Develop a routine to write a function that displays a list of files, organize them in order according to the number of each file, and returns a list of the number of records in the order they were built.
1. Sphere
Design and implement a class called Sphere that contains instance data that represents the sphere's diameter. Define the Sphere constructor to accept and initialize the diameter, and include getter and setter methods for the diameter. Include methods that calculate and return the volume and surface area of the sphere (Volume= 3/4 π r3 , area = 4 π r2 ). Include a toString method that returns a one-line
description of the sphere. Create a driver class called MultiSphere, whose main method instantiates and updates several (at least 5) Sphere objects.

2. Shopping cart
Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use getter and setter methods to access the items (variables) in your Cart Object. After you have created three Cart objects with four items each, you should print the cart contents. Use a method called displayCart() to make it easier to print out the items for each shopping cart. A sample output for the first cart is given below and you may choose your preferred way to show the output of the 3 carts.
************Cart 1*************
---------- Your Shopping Cart ----------
1. Paper 4.99 3
2. Pencils 1.49 2
3. Pens 2.39 2
4. Printer Ink 39.99 4
-----------------------------------------------
Total:
182.69


3.Flights
Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name, flight number, and the flight's origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several (at least 5) Flight objects.
- Temperature
Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have a number of constructor methods: one with two parameters for the two instance variables, and a noargument constructor (set to zero degrees Celsius). Include the following:

(1) two accessor methods to return the temperature one to return the degrees Celsius, the other to return the degrees Fahrenheit use the following formulas to write the two methods, and round to the nearest tenth of a degree:
degreesC = 5(degreesF - 32)/9
degreesF = (9(degreesC)/5) + 32

(2) three mutator or set methods: one to set the value, one to set the scale (F or C), and one to set both;
(3) three comparison methods: an equals method to test whether two temperatures are equal, one method to test whether one temperature is greater than another, and one method to test whether one temperature is less than another (note that a Celsius temperature can be equal to a Fahrenheit temperature as indicated by the above formulas); and
(4) a suitable toString method. Then write a driver program (or programs) that tests all the methods. Be sure to use each of the constructors, to
include at least one true and one false case for each of the comparison methods, and to test at least the following temperature equalities: 0.0 degrees C = 32.0 degrees F, -40.0 degrees C = -40.0 degrees F, and 100.0 degrees C = 212.0 degrees F.
6. Team Roster
Create a program called TeamRoster that uses a class called Roster. Roster should contain a team name and the names of all the players on the team written into one string. Use a method called addTeamMember() to append a new member to your roster string. After creating two rosters with more than 5 members.You should indicate the total number of members in each group near the bottom and label each person with an index (e.g. 1,2,3...), print out the team names and their rosters as show below:

Instructors
1. Aalaa
2. Maha
3. Lamar
4. Sahar
5. Nouf
6. Basma
7. Al-anood
Total Members: 7

Students
1. Student 1
2. Student 2
3. Student 3
4. Student 4
5. Student 5
Total Members: 5

7. Gross And Dozens
Design and implement a class called GrossAndDozens to convert a given number of eggs into the number of gross, the number of dozens, and to the number of left over eggs. If you have N eggs, then you have N/12 dozen eggs, with N%12 eggs left. Write a program that asks the user how many eggs he has and then tells the user how many dozen eggs he has and how many extra eggs are left over.
A gross of eggs is equal to 144 eggs. Extend your program so that it will tell the user how many gross, how many dozen, and how many left over eggs he has. For example, if the user says that he has 1342 eggs, then your program would respond with


Your number of eggs is 9 gross, 3 dozen, and 10

since 1342 is equal to 9*144 + 3*12 + 10.
Write a function called powersOfTwo that prints the first 10 powers of 2 (starting with 2). The function takes no parameters and doesn't return anything.
Write a function called powersOfTwo that prints the first 10 powers of 2 (starting with 2). The function takes no parameters and doesn't return anything.
5- Temperature
Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have a number of constructor methods: one with two parameters for the two instance variables, and a noargument constructor (set to zero degrees Celsius). Include the following:

(1) two accessor methods to return the temperature one to return the degrees Celsius, the other to return the degrees Fahrenheit use the following formulas to write the two methods, and round to the nearest tenth of a degree:
degreesC = 5(degreesF - 32)/9
degreesF = (9(degreesC)/5) + 32

(2) three mutator or set methods: one to set the value, one to set the scale (F or C), and one to set both;
(3) three comparison methods: an equals method to test whether two temperatures are equal, one method to test whether one temperature is greater than another, and one method to test whether one temperature is less than another (note that a Celsius temperature can be equal to a Fahrenheit temperature as indicated by the above formulas); and
(4) a suitable toString method. Then write a driver program (or programs) that tests all the methods. Be sure to use each of the constructors, to
include at least one true and one false case for each of the comparison methods, and to test at least the following temperature equalities: 0.0 degrees C = 32.0 degrees F, -40.0 degrees C = -40.0 degrees F, and 100.0 degrees C = 212.0 degrees F.





6. Team Roster
Create a program called TeamRoster that uses a class called Roster. Roster should contain a team name and the names of all the players on the team written into one string. Use a method called addTeamMember() to append a new member to your roster string. After creating two rosters with more than 5 members.You should indicate the total number of members in each group near the bottom and label each person with an index (e.g. 1,2,3...), print out the team names and their rosters as show below:

Instructors
1. Aalaa
2. Maha
3. Lamar
4. Sahar
5. Nouf
6. Basma
7. Al-anood
Total Members: 7

Students
1. Student 1
2. Student 2
3. Student 3
4. Student 4
5. Student 5
Total Members: 5

7. Gross And Dozens
Design and implement a class called GrossAndDozens to convert a given number of eggs into the number of gross, the number of dozens, and to the number of left over eggs. If you have N eggs, then you have N/12 dozen eggs, with N%12 eggs left. Write a program that asks the user how many eggs he has and then tells the user how many dozen eggs he has and how many extra eggs are left over.
A gross of eggs is equal to 144 eggs. Extend your program so that it will tell the user how many gross, how many dozen, and how many left over eggs he has. For example, if the user says that he has 1342 eggs, then your program would respond with


Your number of eggs is 9 gross, 3 dozen, and 10

since 1342 is equal to 9*144 + 3*12 + 10.



8. Simple Calculator
Write a program that will evaluate simple expressions such as 17 + 3 and 3.14159 * 4.7. The expressions are to be typed in by the user. The input always consist of a number, followed by an operator, followed by another number. The operators that are allowed are +, -, *, and /. Your program should read an expression, print its value, read another expression, print its value, and so on. The program should end when the user enters 0 as the first number on the line.

9. Rational Numbers
Rational numbers are numbers that can be represented as a fraction p / q where p is an integer number and q is a positive integer (q != 0). Design and implement a Java class
RationalNumber for representing such numbers. Implement methods to add and mutliply rational numbers. Implement a method for return the value of a rational number as a double value. Write a driver class to test your class. here is the class details:

Constructor Summary:
RationalNumber(int numerator, int denominator)
Creates a new RationalNumber with given numerator and denominator.
methods summary:
RationalNumber add(RationalNumber rationaleNumber)
Adds the given
rationaleNumber to this RationalenNumber (the object that you created
from RationalNumber Class) and returns the sum as a new RationalNumber.
int getDenominator()
Returns the denominator of this RationalNumber.
double getDoubleValue()
Returns the value of this RationalNumber as a double value.
int
getNumerator()
Returns the numerator of this RationalNumber.
RationalNumber multiply(RationalNumber rationalNumber)
Multiplies the given rationalNumber to this RationalNumber (the object that you created from
RationalNumber Class) and returns the product as a new RationalNumber
1. Sphere
Design and implement a class called Sphere that contains instance data that represents the sphere's diameter. Define the Sphere constructor to accept and initialize the diameter, and include getter and setter methods for the diameter. Include methods that calculate and return the volume and surface area of the sphere (Volume= 3/4 π r3 , area = 4 π r2 ). Include a toString method that returns a one-line
description of the sphere. Create a driver class called MultiSphere, whose main method instantiates and updates several (at least 5) Sphere objects.

2. Shopping cart
Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use getter and setter methods to access the items (variables) in your Cart Object. After you have created three Cart objects with four items each, you should print the cart contents. Use a method called displayCart() to make it easier to print out the items for each shopping cart. A sample output for the first cart is given below and you may choose your preferred way to show the output of the 3 carts.
************Cart 1*************
---------- Your Shopping Cart ----------
1. Paper 4.99 3
2. Pencils 1.49 2
3. Pens 2.39 2
4. Printer Ink 39.99 4
-----------------------------------------------
Total:
182.69


3.Flights
Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name, flight number, and the flight's origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several (at least 5) Flight objects.

4- Leap Year
Design and implement an application that reads an integer value representing a year from the user. The purpose of the program is to determine if the year is a leap year(and therefore has 29 days in February) in the Gregorian calendar. A year will be a leap year if it is divisible by 4 but not by 100. If a year is divisible by 4 and by 100, it is not a leap year unless it is also divisible by 400. For example, the year 2003 is not a leap year, but 2004 is. The year 1900 is not a leap year because it is divisible by 100, but the year 2000 is a leap year because even though it is divisible by 100, it is also divisible by 400. Produce and error message for any input value less than 1582 (the year the Gregorian calendar was adopted).
Please help me with the following assignment;there are Ship, Main, Canallock and Direction classes. make the main method of the main class so that it creates a cana lock, two ships ascending,and two ships descending as separate threads then starts them. the four ships should be given ids 1,2,3 and 4 respectively. compile and execute the project.
sample output:

enter number of elements: 6

enter value: 20
enter value: 34
enter value: 13
enter value: 3
enter value: 12
enter value: 7

the odd numbers are 13, 3, 7
the even number are 20, 34, 12
LATEST TUTORIALS
APPROVED BY CLIENTS