Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

1. Given the following variable definitions,
int x = 3;
double d = 2.0;

what are the types and values of the following expressions? (As an example, the expression x + 2 has type int and value 5.)
(a) 5 / x
(b) 5 / d
(c) 5 / 2 + 1
(d) 4 < x
(e) 5 % x
(f) 4 != x && 2.5 > d
(g) !(3 >= x || true)

2. Write a program (main method) that prompts the user for a "doubled" String, where every character is immediately duplicated. It prints the un-doubled version. Include a loop so that the user is repeatedly prompted. Below is an example transcript.

Please enter a doubled string:
aabbcc
Undoubled is abc
Do you want to play again? (y/n)
y
Please enter a doubled string: SShhaarrkk88mmee
Undoubled is Shark8me
Do you want to play again? (y/n)
n

Plus, extend the previous solution so that it verifies that the input is doubled. If so, it behaves as above.
If not, it prints an appropriate error message.

3. Rewrite the following two code fragments, replacing for loops with equivalent while loops.

(a)
for (int x = 0; x < max; x = x + 3)
{

System.out.println(Math.sqrt(x));
}

(b)
public void listFunction(ArrayList list)
{
for (String e : list)
{
System.out.println (e);
}
}

4. Below is the start of a definition for a Course class. Each Course stores its name, current enrollment, and maximum enrollment. Provide a complete class definition, including a Course constructor and methods so that the following code will compile:

Course introJava = new Course("Java Programming", 15, 25); System.out.println("Course currently has " + introJava.getCurrentEnrollment() + " students"); System.out.println("How many students to add?");
Scanner input = new
Scanner(System.in); int moreStudents = input.nextInt(); introJava.addStudents(moreStudents);
System.out.println("Course currently has " + introJava.getCurrentEnrollment() + "
students"); if (introJava.overFull()){
System.out.println("too many students!");
}

5. When the code fragment above is run, the output might look like:

Course currently has 15 students
How many students to add?
18
Course currently has 33 students too many students!


Public class Course
{
Private String name;
Private int enrollment;
Private int max_enrollment;

// fill in the rest...

}

Java, Programming

  • Category:- Java
  • Reference No.:- M92405218
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As