0% found this document useful (0 votes)
40 views1 page

In Lab Exercise - 01

The document outlines 3 exercises for a Java programming lab, with the first asking students to create a multiplication table from 1 to 10, the second to implement an Author class with name, email, and gender attributes, and the third to write a method to convert byte values to KB, MB, GB or TB with 3 decimal places.

Uploaded by

Paras Dalsaniya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views1 page

In Lab Exercise - 01

The document outlines 3 exercises for a Java programming lab, with the first asking students to create a multiplication table from 1 to 10, the second to implement an Author class with name, email, and gender attributes, and the third to write a method to convert byte values to KB, MB, GB or TB with 3 decimal places.

Uploaded by

Paras Dalsaniya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

In Lab Exercise- Java Programming (3rd Semester)

Exercise-1 (4-point) Time: 45 minute

Implement a Java-main-method that prints out the multiplication table for all numbers from 1 to 10. Use the tabulator
character '\t' to align the values. The output of your method should be as follows:

Exercise-2 (4-point)

A class called Author (as shown in the class diagram) is designed to model a book's author. It contains:
 Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f');
 One constructor to initialize the name, email and gender with the given values;
(There is no default constructor for Author, as there are no defaults for name, email and gender.)
 public getters/setters: getName(), getEmail(), setEmail(),and getGender();
(There are no setters for name and gender, as these attributes cannot be changed.)
 A toString() method that returns "Author[name=?,email=?,gender=?]", e.g., "Author[name=Tan Ah
Teck,[email protected],gender=m]".

Exercise-3 (2-point)

A number of bytes given as a int value should be printed class Converter{


out with at most three digits before the decimal comma. public static void main(String[] args) {
The output for four different values: // call method and print value here
}
123 Byte are 123.0 Byte public static String getSize(long size) {
String s = "";
15323 Byte are 15.323 KByte
double kb = size / 1024;
15323000 Byte are 15.323 MByte double mb = kb / 1024;
1532300001 Byte are 1.532300001 GByte double gb = kb / 1024;
double tb = kb / 1024;
Do not use iterations (only if-else). // implement if-else to return proper value
return s; }}

You might also like