JAVA Practice Problems S.N. Title: Java Program To Find The Biggest of 3 Numbers
The document provides examples of Java programs including finding the biggest of 3 numbers, reversing a number, incrementing digits of a number, converting days to years/weeks/days, checking character types, an Author class with getters/setters, abstract Shape class and subclasses, a discount system for a beauty salon with Customer, Discount, and Visit classes, and string matching using the String library.
Download as XLSX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
15 views
JAVA Practice Problems S.N. Title: Java Program To Find The Biggest of 3 Numbers
The document provides examples of Java programs including finding the biggest of 3 numbers, reversing a number, incrementing digits of a number, converting days to years/weeks/days, checking character types, an Author class with getters/setters, abstract Shape class and subclasses, a discount system for a beauty salon with Customer, Discount, and Visit classes, and string matching using the String library.
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 6
JAVA Practice Problems
S.N. Title 1 Java Program to Find the Biggest of 3 Numbers
Java Program to Reverse a Given Number
2 Java Program to Increment by 1 All the Digits 3 of a given Integer
Java Program to Convert a Given Number of
Days in terms of Years, Weeks & Days 4
Java Program to Check if given Alphabets
are Uppercase or Lowercase or Digits 5
A class called Author is designed to model a book's author. It contains:
6 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; public Author (String name, String email, char gender) {......}
(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=XYZ,email=XYZ@abc.com,gender=f]". Write the Author class. Also write a test driver called TestAuthor to test all the public methods 7 8 Shape shall be defined as an abstract class, which contains: Two protected instance variables color(String) and filled(boolean). The protected variables can be accessed by its subclasses and classes in the same package. They are denoted with a '#' sign in the class diagram. Getter and setter for all the instance variables, and toString(). Two abstract methods getArea() and getPerimeter() (shown in italics in the class diagram). The subclasses Circle and Rectangle shall override the abstract methods getArea() and getPerimeter() and provide the proper implementation. They also override the toString(). Write a test class to test these statements involving polymorphism and explain the outputs. You are asked to write a discount system for a beauty saloon, which provides services and sells beauty products. It offers 3 types of memberships: Premium, Gold and Silver. Premium, gold and silver members receive a discount of 20%, 15%, and 10%, respectively, for all services provided. Customers without membership receive no discount. All members receives a flat 10% discount on products purchased (this might change in future). Your system shall consist of three classes: Customer, Discount and Visit, as shown in the class diagram. It shall compute the total bill if a customer purchases $x of products and $y of services, for a visit. Also write a test program to exercise all the classes.The class DiscountRate contains only static variables and methods 9
10 Java Program to Perform String Matching Using String Library