1.Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff.

acceptClothes accepts the noofClothes as argument & returns the no of Clothes. /*washing machine*/ import java.util.*; class WashingMachine { Scanner input=new Scanner(System.in); public void switchOn () { System.out.println ("The lid is open."); } public void start () { System.out.println ("Start washing ..."); } public void acceptDetergent () { System.out.println("Adding Detergent.. "); start(); } public int acceptClothes() { System.out.println("Enter no of clothes: "); int no=input.nextInt(); return no; } public void switchOff () { System.out.println ("The lid is closed."); } public static void main(String[] args) { WashingMachine wm=new WashingMachine(); wm.switchOn(); int numOFClothes=wm.acceptClothes();

} else { return b-a.acceptDetergent().int b) { if(a>b) { return a-b.out. divide & subtract /*calculator*/ import java.int b) { return a*b. } public int divide(int a. } public int subtract(int a.println(numOFClothes+" clothes get washed"). multiply. } } public int multiply(int a. System.int b) { return a+b.switchOff().Create a calculator class which will have methods add. wm. class Calculation { public int add(int a.*.wm. } } 2.util.int b) .

out. } } 3. } else { return b/a.{ if(a>b) { return a/b. . System. System.println(sub).println(mul). System.out.multiply(5. int div=cal. System.out. int add=cal.divide(5.println(add).10).add(5.10).subtract(5.10). Create a class called Student which has the following methods: i. int mul=cal. Average: which would accept marks of 3 examinations & return whether the student has passed Input name: which would accept the name of the student & returns the name? or failed depending on whether he has scored an average above 50 or not.out.println(div). } } } public class Calculator { public static void main(String []args) { Calculation cal=new Calculation().10). int sub=cal. ii.

} public String getName() { System. } public static void main(String[]args) .out. double avg=tm/3. double m2=input. } return " ". System.util.*.in)./*Student results*/ import java.print("Enter Marks3: ").nextDouble().out.println("Enter Name:"). public class Student { Scanner input=new Scanner(System. String result=average(). double m3=input.nextLine(). System. return name+" get "+result. double tm=m1+m2+m3. if(avg<50) { return "Failed".print("Enter Marks2: ").out. } if(avg>50) { return "Passed". public String average() { System.print("Enter Marks1: ").nextDouble().nextDouble(). String name=input.out. double m1=input.

} } 4.println(nameAndResut).out. } int deposit(int amt) { if (amt < 0) { System. } int withdraw(int amt) { . Similarly. Customer(int bal) { this. The deposit method would acceptattributes amount & balance & returns the new balance which is the sum of amount &balance.Create a Bank class with methods deposit & withdraw.out.{ Student data=new Student(). System. String nameAndResut=data. /*bank calculations*/ import javax. return 1. } bal = bal + amt. class Customer { int bal. return 0.*.bal = bal.println("Invalid Amount").getName(). the withdraw method would accept the attributes amount & balance &returns the new balance ? balance ? amount? if balance > = amount or return 0 otherwise.swing.

int with=Integer. int dep=Integer. Create an Employee class which has methods netSalary which would accept salary & tax asarguments & returns the netSalary which is tax deducted from the salary.parseInt(st1) int bal1=Cust.toString(bal)).out.deposit(dep).showMessageDialog(null. String st2=JOptionPane.println("Invalid Amount").out. } } 5. Cust."Enter the amount to deposit:").check().amt. return 1. } void check() { JOptionPane.withdraw(with)."Enter the amount to withdraw:").parseInt(st2). String st1=JOptionPane. return 0.check(). } if (amt < 0) { System. } } public class Bank { public static void main(String[]args) { Customer Cust=new Customer(1500). } bal = bal .").showInputDialog(null. Cust. Also it has a . int bal2=Cust.showInputDialog(null."Balance:" + Integer. return 1.println("Not sufficient balance.if (bal < amt) { System.

double netpay=salary=tax.out.println("Net Salary is: "+net).out.nextDouble()/100.out.next(). } public static void main(String[] args) { Employee emp=new Employee().print("Enter Grade: "). System. String grade=input. Name. System. double sal=input. } public static String grade( ) { System.out. System. String g=emp.util. System.Create Product having following attributes: Product ID. Add . CreateElectricalProduct having the following additional attributes: VoltageRange and Wattage.*. return grade. /*employee sal & tax*/ import java.taxrate).println("Grade is: "+g).grade(). double net=emp.in).netSalary(sal.print("Enter Salary: "). Category ID and UnitPrice.nextDouble().out. class Employee { static Scanner input=new Scanner(System. return netpay.print("Enter Tax in %: "). double taxrate) { double tax=salary*taxrate. public double netSalary(double salary. } } 6. double taxrate=input.methodgrade which would accept the grade of the employee & return grade.

util. . System. Display the updatedElectricalProduct details. System.int categoryID.println("Name: "+name). int wattage. this. class Product { int productID.wattage=wattage.String name.*. String name.productID=productID.String name. this.double price. double price. this.out. /*electrical product*/ import java. } public void display() { System.voltageRange=voltageRange.double price) { this.categoryID=categoryID. this.println("Product ID: "+productID).categoryID. ElectricalProduct(int productID.out.println("Category ID: "+categoryID). Product(int productID.int voltageRange.a behavior to change the Wattage and price of the electrical product. intwattage) { super(productID. this.name=name.price=price.int categoryID.price).out. int categoryID.name. } } public class ElectricalProduct extends Product { int voltageRange.

int cid=input.println(). int vrange=input.out.println("Enter Price: "). String name=input.println("****Details of Electrical Product****"). Author and Price. System.vrange. Create Periodical whichhas the following additional attributes: Period (weekly.System. System. System. Display the updated periodical details. } } 7. System. System.nextInt().println("Enter Catagory ID: ").Add a behavior to modify the Price and the Period of the periodical.out. Title.util.println("Enter Voltage Range: ")..name.out. System. int pid=input. int wattage=input.println("Enter Wattage: "). /*Book details*/ import java.wattage). System.nextInt().println("Price: "+price).next().) .nextInt().out.out. System. System.nextInt().display(). p.println("Enter Name: "). double price=input.println("Enter Product ID: ").println("Voltage Range: "+voltageRange).price.out. monthly etc.out. System.out. Create Book having following attributes: Book ID. } public static void main(String[] args) { Scanner input=new Scanner(System.*..cid.out.in). class Book { . ElectricalProduct p=new ElectricalProduct(pid.nextDouble().out.out.println("Wattage: "+wattage).

} public void setPrice(double price) { this. } public void setAuthor(String author) { this. String author.price=price. } public String getTitle() { return title.id=id.author=author.title=title. } public String getAuthor() { return author. double price. } public int getId() { return id. } public void setTitle(String title) { this. public void setId(int id) { this. . String title. } public double getPrice() { return price.int id.

out. System. System. String author=input. b. b.nextDouble(). System. int id=input. System. b.out.print("Period: "). System.nextInt(). b.out. String pp=input. .out.out.setId(id).setPrice(price). } public String getTimeperiod() { return timeperiod.setAuthor(author).print("Price: ").next().print("Book ID: "). String title=input.} } class Periodical { String timeperiod.in). Periodical p=new Periodical(). public void setTimeperiod(String timeperiod) { this.setTitle(title).print("Title: ").print("Author: "). } } public class BookInformation { public static void main(String[]args) { Book b=new Book().timeperiod=timeperiod. double price=input.next().next(). Scanner input=new Scanner(System.

Add a behavior tochange the color and loading capacity.println("Author: "+b.out.Create Vehicle having following attributes: Vehicle No. String model. Vehicle(int no. String manufacturer. class Vehicle { int no.manufacturer=manufacturer.out. System. this.setTimeperiod(pp). System.println(). Display the updated truck details.color=color. } } public class Truck extends Vehicle .out.String model.no=no.getId()).String manufacturer. Manufacturer and Color.getAuthor()). String color.p. /*vehicle*/ import java.println("Title: "+b. Createtruck which has the following additional attributes: loading capacity (100 tons).out. this. Model. System.out.println("----Book Information----").out.println("Period: "+p. System.getTitle()).println("Book ID: "+b.out.getPrice()).println("Price: "+b. System. System.out.getTimeperiod()).model=model.String color) { this.println().util. this. System. } } 8..*. System.

nextInt().out.cap).println("Color: ").out.capacity=capacity. System.println("****Truck Details****").println("No = " + no).println("Truck No: ").{ int capacity. String manufacturer=input. } void show() { System.String manufacturer. System.out. System.println("Manufacturer: ").manufacturer. } public static void main(String[] args) { Scanner input=new Scanner(System.color. model.println("Capacity = " + capacity).next(). this. int no=input.String model.out. System.println("Model = " + model).out.show().int capacity) { super( no. int cap=input.println().out. System.in).out.println("Model: ").println("Loading Capacity: "). System.println("manufacturer = " + manufacturer). Truck(int no.out. color).nextInt().String color. System.next(). System.println("Color = " + color). System.out. String color=input. System. String model=input.out. manufacturer. } } .out. System.out.model.t.next(). Truck t=new Truck(no.

format(value)).println("Result is: "+df.nextDouble().text. TataMotors(String category.util. System. "ECONOMY".in). which accepts category of carcustomer is looking for and returns the car Model available in that category.*. Provide a behavior to the program so as to accept any type of numeric values and returns the results. /*power of given number*/ import java. double pow=input. class NumberProgram { public static void main(String[] args) { DecimalFormat df=new DecimalFormat("##. "TATA INDICA" and "TATA NANO" respectively.*.*.String model) .Write a program which performs to raise a number to a power and returns the value. "TATA INDIGO" . "SEDAN".print("Enter Number: ").pow). import java.out. double num=input.9. double value=Math. Scanner input=new Scanner(System. and "MINI" which in turn returns"TATA SAFARI" . System. /*car problem*/ import java. the function shouldaccept the following categories "SUV". class TataMotors { String category.out. } } 10.nextDouble(). String model. System.out.pow(num.util. Write a function Model-of-Category for a Tata motor dealers.##").print("Raise Number's power: ").

"TATA NANO")).add(new TataMotors("MINI".category=category.in). } public String getModel() { return model.out. } public static void ModelOfCategory(ArrayList<TataMotors> list) { Scanner input=new Scanner(System.getCategory().print("Enter Category: "). list.add(new TataMotors("SEDAN".add(new TataMotors("ECONOMY"."TATA INDIGO")). } } } public static void main(String[] args) { ArrayList<TataMotors> list=new ArrayList<TataMotors>().print("Model is: ").getModel())."TATA INDICA")).{ this.out.print(tm. for (TataMotors tm : list) { if(tm.out. String category=input.add(new TataMotors("SUV". .out. list. } public String getCategory() { return category. this. System.println(). ModelOfCategory(list). System. System. list. list.equals(category)) { System.nextLine().model=model."TATA SAFARI")).

} } .

Sign up to vote on this title
UsefulNot useful