Skip to main content

Posts

Showing posts from September, 2013
A program calculates and displays bonus amounts to pay various types of employees. There are 3 separate departments, numbered 1, 2, and 3. Department 1 employees are paid a bonus based on their sales: If their sales amount is over $5000 they get 5% of those sales, otherwise they get nothing. Department 2 employees are paid a bonus based on the number of units they sell: They get $100 per unit sold, and an extra $50 per unit if they sell more than 25 units; if they sell no units, they get nothing. Department 3 employees assemble parts in the plant and are paid a bonus of 10 cents per part if they reach a certain level: Part-time employees must assemble more than 250 parts to get the 10-cent-per-part bonus, and full-time employees must assemble more than 700. Write a set of 3 overloaded methods called getBonus() that works with the program below, according to the specifications described above. public class Calculate {     public static void main(String [] arg...

Create a class called Book to represent a book. A Book should include four pieces of information as instance variables‐a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. In addition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information about the book). You should use this keyword in member methods and constructor. Write a test application named BookTest to create an array of object for 30 elements for class Book to demonstrate the class Book's capabilities.

Create a class called Book to represent a book. A Book should include four pieces of information as instance variables‐a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. In addition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information about the book). You should use this keyword in member methods and constructor. Write a test application named BookTest to create an array of object for 30 elements for class Book to demonstrate the class Book's capabilities. import java.io.*; class Book {     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));     String book_name;     int isbn;     String author;     String publisher; ...

Create a class called Date that includes three pieces of information as instance variables—a month (type int), a day (type int) and a year (type int). Your class should have a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day and year separated by forward slashes(/). Write a test application named DateTest that demonstrates classDate’s capabilities.

Create a class called Date that includes three pieces of information as instance variables—a month (type int), a day (type int) and a year (type int). Your class should have a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day and year separated by forward slashes(/). Write a test application named DateTest that demonstrates classDate’s capabilities. import java.io.*; class Date {     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));     int dat;     int month;     int year;     Date()     {         dat=01;         month=01;         year=2001;     }     pu...

Create a class called Employee that includes three pieces of information as instance variables—a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, set it to 0. Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again

Create a class called Employee that includes three pieces of information as instance variables—a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, set it to 0. Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again . import java.io.*; class Employee {     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));     String f_name;     String l_name;     int sal;     Employee()     {         f_name="sarvajeet";     ...

Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables‐a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. In addition, provide a method named get Invoice Amount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a test application named InvoiceTest that demonstrates class Invoice’s capabilities.

Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables‐a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. In addition, provide a method named get Invoice Amount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a test application named InvoiceTest that demonstrates class Invoice’s capabilities. import java.io.*; class Invoice {     BufferedReader br = new BufferedReader(new InputStreamReader(System.i...

Quicksort program in java

Quicksort program in java  import java.io.*; //import java.util.*; public class QuickSort {    public static void main(String argv[])throws IOException    {        final int SIZE =30;        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));        System.out.println("Enter the number of elements you want to enter");        int n = Integer.parseInt(br.readLine());        int [] arr =new int [SIZE];        System.out.println("Enter the elements of the array");        for (int i=0 ; i < n; i++)          arr[i] = Integer.parseInt(br.readLine());        Quicksort(arr, 0, n-1);        for (int i=0 ; i < n ; i++)    ...

Write a program to compute sum of digits of a given number

Write a program to compute sum of digits of a given number  /* Add the digits of a number*/ import java.io.*; public class Adddigit {     public static void main(String [] args)throws IOException     {         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));         System.out.println("Enter a number to find the sum of digits of a number");         String num = br.readLine();         int a = Integer.parseInt(num);         int sum=0;         while(a!=0)         {             int i=a%10;             sum=sum+i;          ...

Write a Java program that accepts the radius of a circle and displays the options as follows : 1. find diameter of a cicle.(2* radius) 2. find area of circle.( Π* radius * radius) 3. find circumference of a circle.( 2 * Π* radius) 4. exit. Use case statement to implement each option and display the corresponding output

Write a Java program that accepts the radius of a circle and displays the options as follows : 1.   find diameter of a cicle.(2* radius) 2.   find area of circle.( Π* radius * radius) 3.   find circumference of a circle.( 2 * Π* radius) 4.   exit. Use case statement to implement each option and display the corresponding output import java.util.Scanner; public class Circle {     public static void main(String [] args)     {         Scanner input = new Scanner(System.in);         System.out.println("Enter Radius ");         double r = input.nextDouble();         System.out.println(r);         System.out.printf("1.Diameter\n2.circumference\n3.area\n4.exit\n");         System.out.println("Enter number you want "); ...

Write a program that converts a decimal number to Roman number.

Write a program that converts a decimal number to Roman number. import java.util.*; public class Roman {     public static void main(String [] args)     {         Scanner input = new Scanner(System.in);         System.out.println("Enter a Decimal Number");         int num = input.nextInt();//1954         int i=0;         String str="";         String [] roman={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};         int [] decimal={1000,900,500,400,100,90,50,40,10,9,5,4,1};         if(num>0&&num<4000)         {             for(i=0;i<13;i++) ...