banner

Thursday, September 29, 2016

PE8: Inheriting the Car Class

a) Create a super class called Car . The Car class has the following fields and methods. int speed; double regularPrice; String c... thumbnail 1 summary

a) Create a super class called Car. The Car class has the following fields and methods.

  • int speed;
  • double regularPrice;
  • String color;
  • double getSalePrice();

b) Create a subclass of Car class and name it as Ford. The Ford class has the following fields and methods

  • int year;
  • int manufacturerDiscount;
  • double getSalePrice(); //From the salepricecomputed from Car class, subtract the manufacturerDiscount.

c) Create a subclass of Car class and name it as Sedan. The Sedan class has the following fields and methods.

  • int length;
  • double getSalePrice(); //If length >20feet, 5% discount,Otherwise,10% discount.

d) Create MyOwnAutoShop class which contains the main() method. Perform the following within the main() method.
  • Create an instance of Sedan class and initialize all the fields with appropriate values. 
  • Create two instances of the Ford class and initialize all the fields with appropriate values. 
  • Create an instance of a Car class and initialize all the fields with appropriate values.
  • Display the sale prices of all instance.
// Note : Use this and Super() wherever applicable

Monday, September 26, 2016

PE7 : Computing the Employee Salary

Create a class called Employee that includes three pieces of information as instance variables— a first name (typeString), a last n... thumbnail 1 summary

Create a class called Employee that includes three pieces of information as instance variables—
a first name (typeString), a last name (typeString) 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.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.

Thursday, September 22, 2016

PE6: Savings Account Class Operations

/* Create a class SavingsAccount . Use a static variable annualInterestRate to store the annual interest rate for all account holder... thumbnail 1 summary

/* Create a class SavingsAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has ondeposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12. this interest should be added to savingsBalance. Provide a static method modifyInterestRate that sets the annualInterestRate to a new value.

Write a program to test the class SavingsAccount. Instantiate two SavingsAccount objects, saver1 and saver2, with balances of Rs2000.00 and Rs3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest and print the new balances for both savers. Set the annualInterestRate to 5%, calculate the next month’s interest and print the new balances for both savers. */

Thursday, September 8, 2016

PE5: (Array) Calculation of average marks

/* Write a Java program that allows the user to enter up to 10 integer marks into an array. Your main method should call an Average method... thumbnail 1 summary
/* Write a Java program that allows the user to enter up to 10 integer marks into an array. Your main method should call an Average method that returns the average of the marks in the array. */

OUT PUT :


Monday, September 5, 2016

PROGRAM DEMO : SORTING AN ARRAY

import java.util.Arrays ; public class ArrayDemo { public static void main (String[] args) { // initializing unsorted int ... thumbnail 1 summary

import java.util.Arrays;

public class ArrayDemo {

   public static void main(String[] args) {

   // initializing unsorted int array
   int iArr[] = {2, 1, 9, 6, 4};

   // let us print all the elements available in list
   for (int number : iArr) {
   System.out.println("Number = " + number);
   }

   // sorting array
   Arrays.sort(iArr);

   // let us print all the elements available in list
   System.out.println("The sorted int array is:");
   for (int number : iArr) {
   System.out.println("Number = " + number);
   }
   }
}


PE4 : (ARRAY) Find missing numbers

Write a program to find missing numbers in an  array /* To find missing numbers in an array first we need to make sure that arra... thumbnail 1 summary


Write a program to find missing numbers in an  array

/*




  • To find missing numbers in an array first we need to make sure that array is sorted.
  • After sorting we need to check that array each element with next element then we can find the difference.
  • if Array is not sorted :To sort array use Arrays.sort(array);
  • If difference is 1 then no need to do any thing because numbers are in order.
  • If difference is not equal to 1 then we need to print all those numbers or pick those numbers and place it in one array.
  • this would be the logic to find missing numbers in an array
  • Here there may be a chance of array not starting with 1. then we need to check first itself whether array starts with 1 or not if not we need to print 1 to starting element of array.
  • for example int a[]={4,5,6,8}; then we need to print 1 2 3  7.
  • PE 3 : Program to check if a string is a palindrome or not.

    Write a Java program to check if a string is a palindrome or not .  /* Remember a string is a palindrome, if it remains unchanged when ... thumbnail 1 summary

    Write a Java program to check if a string is a palindrome or not
    /* Remember a string is a palindrome, if it remains unchanged when reversed, for example "dad" is a palindrome as reverse of "dad" is "dad" whereas "program" is not a palindrome. Some other palindrome strings are "mom", "madam", "abcba". */