Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

1. Which of the following are not valid Java identifiers, and why?

(a) wolVes

(b) United(there is only one)

(c) 87

(d) 5 3

(e) Real ale

(f) isFound?by

2. A class Television has the following fields:

private TelevisionManufacturer supplier;

private String code

private int screenSize; // in inches

private String type; // e.g. plasma screen

Assume that the class TelevisionManufacturer is available and that this class contains an equals method.

(a) Define a class variable, totalTVs, whose purpose is to keep track of the total number of Television objects constructed during execution of a program that uses the Television class.

(b) Declare a default constructor for this class.

(c) Declare a constructor for this class which has a formal parameter corresponding to each field.

(d) Declare an accessor method called getScreenSize whose purpose is to return the value of the screenSize field of this Television.

(e) Declare a mutator method that sets the type of this Television to a given value.

(f) Declare a method to determine whether or not this Television has been supplied by a given manufacturer.

1. An electronics company needs to implement a simple stock control system. You are required to write a Java application which contains a class called StockItem together with a main method class called StockDemo. Information for each type of stock item consists of:

 inventory identifier (e.g. A654Y);

 quantity in stock (e.g. 350);

 demand rate (quantity removed from stock each working day, assumed constant, e.g. 50);

 re-order quantity (the size of an ordered batch of items, assumed constant, e.g 1000);

 lead-time (number of working days delay between placing and receiving an order for a batch, e.g. 5).

The class StockItem should include fields for each of the above data items and should also include each of the following:

 a default constructor that sets all fields to null or zero as appropriate;

 a constructor with arguments for all fields;

 set methods for all fields;

 accessor methods for each of the fields;

 a method to update the stock quantity when a batch is received;

 a method called isReOrderPoint( ) that returns true if a batch needs to be re-ordered for this stock item and false otherwise;

 a toString method that returns a description of this StockItem.

Add Java statements to your main method to thoroughly test your class.

2. A class Weather is to have as one of its fields an array called rainfall. For each

Weather object the instance variable corresponding to the rainfall field is used to hold the rainfall (in mm) for each of the 12 months in the year specified by a field, year, at the location specified by a field, site.

Write a Java application containing a main method class called WeatherDemo and a Weather class. In addition to the fields specified above your Weather class should contain:

 A constructor with arguments for the year and site fields; this constructor should also create a rainfall array with all elements initialised to zero;

 A mutator method setRainfallForMonth which, given an int, month, in the range 1 to 12, representing a month in a year, sets the appropriate element of the rainfall array of this Weather object to a value given as the second argument of the method. If month is not in the range 1 to 12, the rainfall array is not modified.

 A method getAverageRainfall to return the average rainfall over the year for this Weather object.

 A method getMonthOfMaxRainfall to return as a String the name of the month having the maximum rainfall during the year for this Weather object.

 a toString method.

Add Java statements to your main method to thoroughly test your class.

3. Data for a number of people is given as a string. The data for each person is given by two fields, a forename and a surname separated from each other by a forward slash character. The end of each person's data is marked by a # character. The following is an example of such a String:

Write and test a Java application containing a main method class called ArrayOfStringsDemo and a class called Name.

Name is to have two fields, one for a forename and one for a surname, and should include a constructor with formal arguments corresponding to the fields, an accessor method for each field and a toString method.

In addition to the main method, ArrayOfStringsDemo should contain a static method called findName which takes two arguments. The first argument is an array of elements of type Name and the second argument is a Name. findName returns the index of the element in the given array whose firstname and secondname are the same as those of the Name given as the second argument. If a match is not found, -1 is returned.

You main method should implement the following steps.

(a) Prompt for and read in an integer representing the number of rstname/secondname pairs in a string to be input; store the input value in an int n.

(b) Prompt for and read in a String with the above format and containing n firstname/secondname pairs.

(c) Construct an array of Names of size n called testArray.

(d) For each successive firstname/secondname in the input String, construct a Name object and assign this to the next element in testArray.

(e) Use an appropriate selection of test Names to thoroughly test your findName method.

Java, Programming

  • Category:- Java
  • Reference No.:- M9523534

Have any Question?


Related Questions in Java

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

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 ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

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 ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

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 ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

  • 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