Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
226 views

Lab 1 PDF

This document provides instructions for several Java programming exercises: 1. It asks questions about class names, file names, main methods, and print statements. 2. It instructs the reader to create classes with void display methods and objects to invoke them in a Main class. 3. It provides partial code for a class to generate random data and find min, max, sum, and average values. 4. It provides a UML diagram and asks the reader to implement the class and write a MyApp class. 5. It asks the reader to write a Temperature class with a method to convert from Fahrenheit to Celsius. 6. It provides code to test the Temperature conversion

Uploaded by

Amirul Amin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
226 views

Lab 1 PDF

This document provides instructions for several Java programming exercises: 1. It asks questions about class names, file names, main methods, and print statements. 2. It instructs the reader to create classes with void display methods and objects to invoke them in a Main class. 3. It provides partial code for a class to generate random data and find min, max, sum, and average values. 4. It provides a UML diagram and asks the reader to implement the class and write a MyApp class. 5. It asks the reader to write a Temperature class with a method to convert from Fahrenheit to Celsius. 6. It provides code to test the Temperature conversion

Uploaded by

Amirul Amin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1

Lab 1:

1. Write and run the source code given below.

a. What is a class name?


b. What is a file name?
c. What is a main method?
d. What does System.out.println(“World!”) do?

1
2

2. Class, Object and void method

A posible class name Posible object


Image
names
1. Write a java
application
based on the
class name.

2. Inside the
class, create one
void method
named display.
The method will
print the name
of the image.
Example “This is
a Car”

3. Write one
application
named
Main.java. the
Main.java
consists main
method. Create
objects of four
classes and
invoke display
method in Main
method.

3. Complete the MyFirstAnalysis.java below.

package firstanalysis;

import java.util.Random;

2
3

/**
*
* @author msa
*/
public class MyFirstAnalysis {

public int [] generateRandomData()


{
int inputData[] = new int[10];

Random
for(intgenerateRandom = new Random();
i =0; i<10; i++)
{
inputData[i] = generateRandom.nextInt(100);
}

return inputData;

public void findMaxMinSumAverage(int [] inputData)


{
/*
* 1. Write your code to display Min, Max, Sum and Average Value
*
}

public static void main(String[] args) {

MyFirstAnalysis firstAnalysis = new MyFirstAnalysis();


for(int value : firstAnalysis.generateRandomData())
{
System.out.println("Values : "+value);
}
}
}

4. Based on the UML class given below, write the java implementation class. Then, write
MyApp.java given below. Compile and run MyApp.

3
4

MyApp.java

5. Write one class named Temperature.


6. Inside the temperature class, write one method to convert farenheit to celcius.

Method Name public double convertTemperaturetoCelcius(double fahrenheit)


Input of method double
process celcius = (5.0/9)*(fahrenheit-32)
Output Temperature in celcius

4
5

After finish question 5 and 6, run the Exercise1.java application below.

5
6

7. Add the related source code for converting farenheit to celcius into GuiTemperature class
below. Compile and run GuiTemperature.

You might also like