Thursday, December 14, 2006

Introduction

Hi Dear-all,
I am Pravinth. Am a graduate student.i want to tell you all why i have created this blog? Its beacuse of my passion about java and also i really want to do something, really want to contribute something to the society.So here i am to help others- So whom can i able to help? or who can get my help?.So what are my strengths? so that i can use it to help others? I am really good in core basic java-or at least i think so. but i am sure that i am not an expert in java still i have to learn more. So here i am to do some little java programs for you-who are totally new to it. So how am i going to do it? do i have enough time? Definitely not! so one way to do this is,-who are totally new to java send me your class programs or doubts in basic core java- if i know i will do the program and post it in here -in my blog with clear explanations.I have been greatly inspired by my friend Suleman. so let us start our work...so who is the first one going to finish his java program with our help in less time??? You can ask your doubt in XML also...

119 comments:

chris1980 said...

Mr Pravinth.
What a personality. Thanks for all the help you have given me in the past in java programs. and one day you will see me helping these people out also.

PRAVINTH G said...

Thank you -my dear friend Sule! I won't forget your help...Thank You very much!

Noel said...

i need help in writing a program as soon as possible. i am creating a car dealership program. The program will have a menu.
1) Add a car
2) View a car
3) delete a car
4) quit

we have to use Arraylist or array.
when a user clicks on option 1 he should enter the make of the car, model and year and it should be stored somewhere so then later on if user enters option 2 he can view the whole list of car or may be we can add a search option (make) enter the make and it will display the list of cars for that make.
ThankYou.

PRAVINTH G said...

yes!
we can easily create that 4 menu items..i mean add,view,del,quit....
why and where do you want to use array/arrayList???
so you want to store the car details....we can store them in a text file or in any database for example..MySQL, MS-ACCESS,...
if we store the details in a text file, there won't be any need to use databse.. but if the details are more then using file will slowdown the search,retrieval,update operations... so i recommend you to use a database....

Noel said...

Thanks. This is my assignment. We just started learning Arraylist and Arrays. my teacher told us to create a program in which a user will be able to do the following.
1)Add a car ( if user enter 1 then he will have another menu which are as follow:
1) Make of the car.
2) model of the car.
3) year of the car. )
************************
2) View Car Details ( If user enter option 2 he will be asked to enter the Make of the car. and then the program should return all the cars matching with the make.

3) delete a car ( if a user enter 3 he will be asked to enter the make, model and year of the car to delete)

4) quit( if a user enter 4 the program should quit).

Our instructor did not say where to store but i think the txt file will be a good option to store the data.

Thanks

PRAVINTH G said...

i have added the program in a seperate post please continue in there.... Thank You!

Chris said...

Wow great work pravinth.

PRAVINTH G said...

Thank you dear Friend-sule!

Chris said...

Hello. These are the answers for the 2 programs which are on the test.
1) Product
*******************************
class ProductTester
{
private String name;
private double price;

ProductTester (String name, double price)
{
this.name = name;
this.price = price;
}

public String getName()
{
return name;
}

public double getPrice()
{
return price;
}
public void setPrice(double n)
{
price = n;
}

public void print()
{
System.out.println("Product Name: " + getName());
System.out.println("Product Price: " + getPrice());

}
}

class Product
{
public static void main(String[] args)
{
ProductTester a = new ProductTester("Toaster", 29.95);
ProductTester b = new ProductTester("Oven", 35.50);
a.print();
a.setPrice(a.getPrice()-5.00);
a.print();
b.print();
b.setPrice(b.getPrice()-5.00);
b.print();
}
}
*******************************

Chris said...

2nd problem.
******************************
class SquareTester
{
private double height;
private double width;

public SquareTester(double height, double width)
{
this.height = height;
this.width = width;
}

public double getArea()
{
return width*height;
}

public double getPerimeter()
{
return 2 *(height + width);
}

public void print()
{
System.out.println("The total area is " + getArea());
System.out.println("The total periemeter is " + getPerimeter());
}
}

class Square
{
public static void main(String[] args)
{
SquareTester a = new SquareTester(10.0, 20.0);
a.getArea();
a.print();

}
}
*************************

Chris said...

i will be there in the class at 9:30 tomorrow since Dr Yu is out of town. register yourself and post any kind of assignments or questions you have concerning Java. Pravinth and i will try our best to solve your problems. One person took the step of registring himself and pravinth provided the code for his assignment so please register and post your questions

hari said...

i am hari , studying in udc, trichy, my frient ar. senthil give this blogspot id.
i am new to java . so please sent below programs in a simple coding.
my mail id: hariji_bhv@yahoo.com

15.Prepare the college profile using HTML.
14.Use the Java script to make a calculator.
13.Write a program which will open an existing file and then append text to that file.
available in the applet class and the methods in the Audio clip interface.
12.Write an Applet which will play 2 sound notes in a sequence continuously use the play ( ) methods
and 2 buttons ok & cancel for accepting user input. Validate or cancel the dialog box.
passwordtoconnectto some on line service. The dialog box consists of two fields user name password
11.Createanapplicationwhich consists of a dialog box that could be used to obtain an user name and a
down). Also provide a mechanism whereby the user can change the colors of selected regions.
tothe selection should be highlighted by enveloping them in rectangles (Use mouse events like mouse
10.Load an image on to applet. As the user selects portions of this image, rectangular regionscorresponding

Chris said...

hari i think this is not an assignment but a big project which will take some time as you know we are students like you. have you done any work yet if not please specify the date when this task should be completed.
Thanks

Noel said...

I got 4 questions to do. here are my 4 questions
1) implement a class car with following properties. a car has a certain fuel efficiency (mesaured in miles/gallons) and a certain amount of fuel in the gas tank. the efficiency is specified in the constructor and the initial level is 0. supply a method drive that stimulates driving the car for a certain distance, reducing the fuel level in the gas tank. also supply method getGas, returning the current fuel level, and addGas, to tank up. sample usage
Car myHybrid = new Car(49);
myHybrid.addGas(20);
myHybrid.addGas(100);
System.out.println(myHybrid.getGas());

Noel said...

2) implement a class RoachPopulation that stimulates the growth of a roach population. the constructor takes the size of the initial roach population. the waitForDoubling method stimulates a period in which the population doubles. The spray method simulates spraying with insecticide, which reduces the population by 10%. the getRoaches method returns the current number of roaches. implement the class and test a program that simulates a kitchen that starts out with 10 roaches. Wait, spray, print the roach count. Repeat Three times.

Noel said...

3) write the following java expressions in mathematical notation:
a) dm = m * (MAth.sqrt(1 + v /c) / Math.sqrt(1-v/c) -1));
b) volume = Math.PI * r * r * h;
c) volume = 4 * Math.PI * Math.pow(r,3) /3;
d) p = Math.atan2(z, Math.sqrt(x * x + y * y));

Noel said...

4) Give an example of integer overflow. would the same example work correctly if you used floating point?. give an example of a floating point round off error. would the same work correctly if you used integers ? for this exercise you should assume that the values are represented in a sufficiently small unit, such as cents instead of dollars, so that the values dont have a fractional part.

Noel said...

5) Let n be an integer and x a floating point number. explain the difference between
n = (int) x;
and
n = (int) Math.round(x);

Chris said...

noel give me 3 days i will try to do all the assignments for you.

Chris said...

here is the code for question 1 noel.
*********************************
class Car
{
private double fuelEff;
private double drive;
public double gasTank;

public Car(double rate)
{
fuelEff= rate;
gasTank = 0;
}
public void drive (double amountDrive)
{
drive = amountDrive;
gasTank -= drive/fuelEff;
}
public void addGas(double amountPump)
{
gasTank += amountPump;
}

public double getGas()
{
return gasTank;
}
}

class CarEfficiency
{
public static void main(String[] args)
{
Car myHybrid = new Car(49);
myHybrid.addGas(20);
myHybrid.drive(100);
System.out.println(myHybrid.getGas());
}
}
************************

Chris said...

2)
**********************************
//RoachPopulation.java
public class RoachPopulation {
private double myCount;

public RoachPopulation(double count) {
myCount = count;
}

public double getCount(){
return myCount;
}

public void waitTime(){
myCount = myCount * 2;
}

public void spray(){
myCount = myCount * 0.9;
}

public String toString(){
return "Roach Count = " + myCount;
}
}

//RoachPopulationTest.java
public class RoachPopulationTest {
public RoachPopulationTest() {
}
public static void main(String[] args) {
RoachPopulation r1 = new RoachPopulation(10);
System.out.println("Roach Count = " + r1.getCount() );
r1.waitTime();
r1.spray();
System.out.println(r1);

r1.waitTime();
r1.spray();
System.out.println(r1);

r1.waitTime();
r1.spray();
System.out.println(r1);

r1.waitTime();
r1.spray();
System.out.println(r1);


}

}

Chris said...

5)
n = (int) x;
x is floating point number. this is the concept of casting in java where x is going to change in Int.
n = (int) Math.round(x);
in this also same thing is happening except the value for x is going to be rounded to the nearest whole number. for eg 3.4 (Math.round(x)) will output 3(which is int using casting in java).

Chris said...

hey pravinth i have done all the questions except 4 i can't understand it so please do it.

Chris said...

pravinth i recieved an email from this guy who was so desperate to complete his project. guess what i spent 1 hour yesterday just to help this newbie :). he was really happy and wanted to repay to me and i said dont worry just prey :). here was the assignment not hard but lengthy.
*********************************
Word Doc project
• Write an original program that contains two files. One file should be named TermProjectXXX.java and the other file should be named StudentXXX.java. The TermProjectXXX class should contain the main method. The main method should use a switch statement along with a menu to give the user access to the activities listed on the menu. The program should return to the menu upon completion of an activity so the user can select another activity listed on the menu or select from the menu the option to exit the program.
• One menu option should call a method in the StudentXXX class that outputs the programmer's name, year in school, home state and college major.
• Another menu option should call a method in the program class that enables the user to enter up to ten golf scores. It should also enable the user to enter -1 to quit entering scores if they have less than ten to enter. The method should output a list of the scores entered to the DOS screen and calculate the average of all the golf scores entered. It should also output the average of all the golf scores entered rounded to the nearest tenth of a point using a printf function.
• Another menu option should initialize the variables using a constructor while instantiating three StudentXXX objects. The StudentXXX objects should each receive five arguments including the students first name, last name and three decimal value scores (e.g. 88.5, 87.0, 95.7 ). The scores represent the grades they received on exams where the maximum number of points they could receive on each exam was 100 points. The objects should calculate the average test score for the three exams. The objects should also output the average test score and a letter grade for the average test score for each student. If the average test score was 90 or higher it should indicate the student received an A. If the average test score was at least 80 but less than 90 the student should receive a B. If the average test score was at least 70 but less than 80 the student should receive a C. If the average test score was at least 60 but less than 70 the student should receive a D. If the average test score was less than 60 the student should receive an F.
• Another menu option should call a method in the program class that has the user enter the year in which they were born. The method should use a loop to output every year evenly divisible by five after their birth year along with their age on January 1 of every year evenly divisible by five until and including the year 2010.
• Another menu option should call a method in the program class that has the user enter their age as a decimal value ( e.g. 35.5 or 27.33). The method then uses a Math class method to round their age to the nearest whole number and output the rounded age and indicate whether the user is young ( 0 to less than 40), middle aged (at least 40 but less than 60) or a senior citizen (60 or older).
• Another menu option should have the user enter three integer values on the keyboard that are passed as arguments to a method in the program class named myCircles. The method myCircles should have three integer parameters to represent the radius of each of three circles. The method should indicate if circle one is equal to or not equal to circle two and to circle three as well as whether circle two is equal to or not equal to circle three. Finally the method should calculate and output the area of each circle. The formula for the area of a circle is 3.14 * radius * radius.
*********************************

Chris said...

here is the TeamProject class.
import java.util.Scanner;
class TeamProject
{
public static void main(String[] args)
{
int choice =0;
Scanner s = new Scanner(System.in);
Student stu = new Student();
do
{
System.out.println("JAVA ACTIVITIES ESPECIALLY JUST FOR YOU! ");
System.out.println(" Please enter your selection. ");

System.out.println("");
System.out.println("1 - Programmer's Info");
System.out.println("2 - Golf Scores");
System.out.println("3 - Student's Test Scores");
System.out.println("4 - Birth Year");
System.out.println("5 - Age");
System.out.println("6 - Circles");
System.out.println("7 - Exit");
System.out.println("\n");
choice = s.nextInt();

if(choice ==1 )
{

stu.printProgrammer();
}
else if(choice ==2)
{
boolean done = false;
System.out.print("Enter atleast 10 scores or -1 to quit: ");
while(!done)
{

String input = s.next();
if(input.equalsIgnoreCase("-1"))
done = true;
else
{
double x = Double.parseDouble(input);
stu.add(x);
}
}
System.out.println("THe average is " + stu.getAverage());
}

else if (choice == 3)
{
char grade='A';
Student stud = new Student("suleman", "zia", 88.5, 87.0, 95.7 );
double average = stud.getAverageStudent();
if(average >=90)
{
grade = 'A';
System.out.println("Name: " + stud.getFirst() + "\nLast: " + stud.getLast() +
"\nAverage: " + average + "\nGrade " + grade );
}
else if(average >= 80 && average <=90)
{
grade = 'B';
System.out.println("Name: " + stud.getFirst() + "\nLast: " + stud.getLast() +
"\nAverage: " + average + "\nGrade " + grade );
}
else if(average >=70 && average <=80)
{
grade = 'C';
System.out.println("Name: " + stud.getFirst() + "\nLast: " + stud.getLast() +
"\nAverage: " + average + "\nGrade " + grade );

}

else if(average >=60 && average <=70)
{
grade = 'D';
System.out.println("Name: " + stud.getFirst() + "\nLast: " + stud.getLast() +
"\nAverage: " + average + "\nGrade " + grade );

}

else{
grade = 'F';
System.out.println("Name: " + stud.getFirst() + "\nLast: " + stud.getLast() +
"\nAverage: " + average + "\nGrade " + grade );

}
}

else if(choice == 5)
{
stu.printAge();
}

else if(choice == 6)
{
System.out.println("Enter the value for 1st circle ");
String circle1 = s.next();
System.out.println("Enter the value for 2nd circle ");
String circle2 = s.next();
System.out.println("Enter the value for 3rd circle ");
String circle3 = s.next();
stu.myCircle(circle1, circle2, circle3);
}
}while(choice != 7);
}
}

Chris said...

and here is the Student class

*********************************
import java.util.Scanner;
import java.lang.*;
public class Student
{
private double sum;
private double maximum;
private double count;
private String first;
private String last;
private double score1;
private double score2;
private double score3;
Scanner s = new Scanner(System.in);
public Student()
{
sum = 0;
count = 0;
maximum =0;
}

public Student(String first, String last, double score1, double score2, double score3)
{
this.first = first;
this.last = last;
this.score1 = score1;
this.score2 = score2;
this.score3 = score3;
}

public double getAverageStudent()
{
double avg = score1 + score2 + score3 /3;
return avg;
}
public String getFirst()
{
return first;
}
public String getLast()
{
return last;
}


public void printProgrammer()
{
System.out.println("Enter the programmer name ");
String name = s.next();
System.out.println("Enter The year ");
int year = s.nextInt();
System.out.println("Enter the state ");
String state = s.next();
System.out.println("Enter your major ");
String major = s.next();
System.out.print("Name: " + name + "\nYear: " + year + "\nState: "
+ state + "\nMajor: " + major + "\n");
}

public void printAge()
{
String looks = "";
System.out.println("Enter your age please ");
double age = s.nextDouble();
double ages = Math.round(age);
if(age<=40)
{
looks = "Young";
}
else if(age >=40 || age <=60)
{
looks = "older";
}
else
{
looks = "Senior";
}
System.out.println("Age " + ages + " looks" + looks + "\n");
}

public void myCircle(String circle1, String circle2, String circle3)
{
if(circle1.equals("circle2") && circle2.equals("circle3") || circle1.equals("circle3"))
System.out.println("THey are equal");
else
System.out.println("They are not equal");
}

public double getArea(double radius)
{
return 3.14 * radius * radius;
}

public void add(double x)
{
sum = sum + x;
if(count == 0 || maximum < x)
maximum = x;
count++;
}

public double getAverage()
{
if(count==0)
return 0;
else return sum/count;
}
}

Chris said...

i was learning arraylist and i tried to write the same program you wrote for noel. hope you like it still incomplete since i got busy with other things.
here is the main CarTester class

***********************************
import java.util.Scanner;
class CarTester
{
public static void main(String[] args)
{
Car car = new Car();
int choice, year;
String make, model;
Scanner s = new Scanner(System.in);
System.out.print("****************************************************\n");
System.out.println("\t\tWellcome to my Car Program ");
System.out.println("****************************************************");
do{
System.out.println("1) Add a car ");
System.out.println("2) View a car ");
System.out.println("3) Delete a car ");
System.out.println("4) Find a car ");
System.out.println("5) Exit ");
System.out.print("Enter the choice number: ");
choice = s.nextInt();
if(choice==1)
{
System.out.println("Enter the make of a car ");
make = s.next();
System.out.println("Enter the model of a car ");
model = s.next();
System.out.println("Enter the year of a car ");
year = s.nextInt();
car.add(new CarAccount(make, model, year));
}
else if(choice==4)
{
System.out.println("Enter the year of the car to find");
year = s.nextInt();
CarAccount a = car.search(year);
if(a==null)
System.out.println("No car found ");
else
System.out.print("Make: " + a.getMake() + "\n" + "Model: " + a.getModel() +
"\n" + "Year: " + a.getYear());
}
}while(choice!=5);
// String make = s.nextLine();
}
}

Chris said...

CarAccount class

***********************************
import java.util.Scanner;
public class CarAccount {

private String make;
private String model;
private int year;

public CarAccount(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}

public String getMake()
{
return make;
}

public String getModel()
{
return model;
}

public int getYear()
{
return year;
}

}

Chris said...

and here is my Car class

******************************
import java.util.ArrayList;

public class Car {

private ArrayList|CarAccount| account;

public Car()
{
account = new ArrayList|CarAccount|();
}

public void add(CarAccount a)
{
account.add(a);
}

public CarAccount search(int year)
{
for(CarAccount a : account)
{
if(a.getYear() == year )
return a;
}
return null;
}

public void remove(CarAccount a)
{
account.remove(a);
}

}

Chris said...

all the | is <> i dont y the blog is not acception

Suleman Zia said...

This is suleman zia same as chris1980 :). chris is my nickname.

ji said...

hi this is jinal i am studying in std 10th and do have computer subject in which we r taught java
theroy as well as programs
and will be appearing for icse board in march
so would like to hav a help
so can u plzz write a program on calculator with all its functions plzz as this my board assinment need to give by 11 of july

JIZ said...

HI
I AM STUDENT OF STD 10TH AND HAS OPTED COMPUTERS IN WHICH WE R TAUGHT JAVA
AS BEING NEW TO IT I NEED SOME HELP PLZZ AS I HAVE GOT TO SUNMIT MY BOARD ASSINMENTS BY 11 OF JULY
MY PROGRMS TOPICS R :
1.ALL THE FUNCTIONS OF A CALCULATOR
2.WRITE A JAVA PROGRAM METHOD RESULT THAT TAKES THE ROLL NUMBER , NAME AND MARKSOF THREE SUBJECTS:
ENGMARKS
MATMARKS
COMPMARKS
AS PARAMETERS FROM THE MAIN.THE METHOD RETURNS THE PERCENTAGE OF THE STUDENT ,ASSUMING THAT MAXIMUM MARKS FOR EACH SUBJECT OUT OF 100

PRAVINTH G said...

Hi Ji,
Calculator program will take some more time... i will ask sule if he has then he may put that in compzia.org
Here is a model one for the second one...
----------------------------------
import java.io.*;
import java.util.*;
/* Note: Use this as a model one and make one which fulfils all your req...
*/

public class forJI{
/* This function takes 3 marks as input and returns average. Hope you know--> If you want to call this function directly from the main function..then you should use 'static'
*/
double calculatePercentage(int mark1, int mark2,int mark3){
return (double)(mark1+mark2+mark3)/3;
}

/* This is a constructor getting a student name , roll no, then three mark..then display the average by calling the calculatePercentage function..
*/
forJI(){
System.out.println("Enter the Student Name:");
Scanner scan=new Scanner(System.in);
String name=scan.nextLine();
System.out.println("Enter the Student Roll No:");
String RollNo=scan.nextLine();
System.out.println("Enter the EngMarks:");
int mark1=Integer.parseInt(scan.nextLine());
System.out.println("Enter the MathMarks:");
int mark2=Integer.parseInt(scan.nextLine());
System.out.println("Enter the CompMarks:");
int mark3=Integer.parseInt(scan.nextLine());

System.out.println("---------OUTPUT--------------");
System.out.println("Student Name: "+name);
System.out.println("Student Roll No.:"+RollNo);
System.out.println("Average Marks:"+calculatePercentage(mark1,mark2,mark3));
System.out.println("-----------------------------");

}

/* This is the main function just to call the constructor...
*/
public static void main(String args[]){
new forJI();
}
}

Suleman Zia said...

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class CalculatorFrame extends JFrame
{
public static void main(String[] args) {
JFrame frame = new CalculatorFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Calculator");
frame.setVisible(true);
}
public CalculatorFrame()
{
JPanel calPanel = new JPanel();

calPanel.setLayout(new GridLayout(4, 4));

createControlPanel();
pack();
}


private void createControlPanel()
{
// the panel for holding the user interface components
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(5, 4));

buttonPanel.add(makeDigitButton("7"));
buttonPanel.add(makeDigitButton("8"));
buttonPanel.add(makeDigitButton("9"));
buttonPanel.add(makeOperatorButton("/"));
buttonPanel.add(makeDigitButton("4"));
buttonPanel.add(makeDigitButton("5"));
buttonPanel.add(makeDigitButton("6"));
buttonPanel.add(makeOperatorButton("*"));
buttonPanel.add(makeDigitButton("1"));
buttonPanel.add(makeDigitButton("2"));
buttonPanel.add(makeDigitButton("3"));
buttonPanel.add(makeOperatorButton("-"));
buttonPanel.add(makeDigitButton("0"));
buttonPanel.add(makeDigitButton("."));
buttonPanel.add(makeOperatorButton("="));
buttonPanel.add(makeOperatorButton("+"));

display = new JTextField("0");
display.setEditable(false);

add(display, BorderLayout.NORTH);
add(buttonPanel, BorderLayout.CENTER);

lastValue = 0;
lastOperator = "=";
start = true;
}

public void calculate(double n)
{
if (lastOperator.equals("+"))
lastValue += n;
else if (lastOperator.equals("-"))
lastValue -= n;
else if (lastOperator.equals("*"))
lastValue *= n;
else if (lastOperator.equals("/"))
lastValue /= n;
else if (lastOperator.equals("="))
lastValue = n;

display.setText("" + lastValue);
}


public JButton makeDigitButton(final String digit)
{
JButton button = new JButton(digit);

class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if (start)
display.setText(digit);
else
display.setText(display.getText() + digit);
start = false;
}
}

ButtonListener listener = new ButtonListener();
button.addActionListener(listener);
return button;
}


public JButton makeOperatorButton(final String op)
{
JButton button = new JButton(op);

class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if (!start)
{
double x = Double.parseDouble(display.getText());
calculate(x);
start = true;
}

lastOperator = op;
}
}

ButtonListener listener = new ButtonListener();
button.addActionListener(listener);
return button;
}

private JTextField display;
private double lastValue;
private String lastOperator;
private boolean start;
}

Suleman Zia said...

i have posted the calculator program. if you need any more help or if anyone can find any errors or need to upgrade more please post back.

Suleman Zia said...

Hey Ji. Spread the word for this blog to your classmates. if you need more help please post back your assignments. we will try our best to do asap.

fizkiz07 said...

Hi Mr. Pravinth you are and your friend are excellentt people. I have a program that my teacher assigned and I cannot figure it out. Ill give you the directions for it.

Define a class called Counter. Object of this class is used to count things. so it records a count that is a nonnegative whole number. Include methods to set the counter to 0, yo increase the count by 1, and decrease the count by 1. Be sure that no method allows the value of the counter to become negative. Also include an accssor method that returns the current count value., as well as a method that outputs the count on the screen. The only method that can set the counter is the one that sets it to zero. Write a program to test your class definition.

These were the dirction given by my instructor. I would appreciate if you could write this program for me ASAP. Thank you

PRAVINTH G said...

Hi fizkiz, Me ,sule we both were busy .. now only i got a time and here is the code....
Leave your comments...

import java.io.*;
public class Counter{
private int count=0;

public void clearCount(){
this.count=0;
}
public void increaseCount(){
this.count++;
}
public void decreaseCount(){
if(this.count>0)
this.count--;
}
public int getCount(){
return this.count;
}
public void printCount(){
System.out.println("Count="+this.count);
}
//Constructor
Counter(){
while(true){
System.out.println("Enter your choice: \n 1 to Terminate \n 2 to set Counter value"+
" to zero \n 3 to increase Counter Value \n 4 to decrease "+
"counter value \n 5 to print current counter value ");
/* If u know scanner better use it.. the system in which i am currently checking this code has only old java version..no scanner class.. so
using BufferedReader...*/

BufferedReader bf=null;
int choice=0;
try{ bf=new BufferedReader(new InputStreamReader(System.in));
choice=Integer.parseInt(bf.readLine());
}catch(Exception e){e.printStackTrace();}
switch(choice){
case 1: return;
case 2: clearCount(); break;
case 3: increaseCount(); break;
case 4: decreaseCount(); break;
case 5: printCount(); break;
default: System.out.println("Invalid Input"); break;
}
}
}
public static void main(String args[]){
new Counter();
}
}

fizkiz07 said...

Hi thank you for the last program i have another program to do now.
Here are the instructions.

Write a Temperature class that has two parameters; a temperature value(a floating-point number) and a character for the scale, either 'C' or 'F' for farenheit. The class should have four constructor methods; one for each instance variable(assume 0 degrees if no value is specified for the two instance varibales, and a default constructor(set to 0 degrees Celsius). Include (1) two accesor methods to return the temperature, one to the degrees Celsius, the other to return the degrees Farenheit -- use the formulas 5(degrees Farenheit - 32)/9 for degrees celsius and (9((degrees Celsius)/5) + 32 for degrees Farenheit to write the two methods, and round to the nearest tenth of a degree;(2) three reset methods, one to set the value, one to set the scale('F' or 'C'), and one to set both; and (3)three comparison methods, one to test wether two temperatures are equal, one to test wether one temperature is greater than another, and to test wether one temperature is less than another. Then write a driver program that tests all methods. Be sure to use each of the constructors, to include at least one true and one fals case for each comparison method, and to test at least the following temperature equalities: 0.0 degrees C = 32.0 degrees F, -40.0 degrees C = -40.0 degrees F, and 100.0 degrees C = 212.o degrees F.

I know this program is long but if you could do it i would really appreaciate it. Thank you.

PRAVINTH G said...

Hi FizKiz i added the new program (Temperature Conversion ) in a new Thread. Please leave your comments in that thread.. you can find the program at:
http://freejavaprograms.blogspot.com/2007/10/temperature-conversion-program.html

fizkiz07 said...

Hey Pravinth thank you for the last program it was excellent. Your program was nicely structured, I have another program for you.

Define two derived classes of the class Figure.( I have provided the class Figure for you.) Your two classes will be called RightArrow and LeftArrow. The size of the arrow is determined by two numbers, one for the length of the "tail," which is 12 and for the width, which is 7. The width of the base cannot be an even number, and your constructors and mutator methods should check to make sure that it is alway odd. Write a test program for each class that tests all the methods in the class. You can assume that the base of the arrowhead is 3 or more.
Here is an example of the arrow to be drawn.
*
* *
* *
************ *
* *
* *
*
public class Figure
{
private int offset;

public Figure()
{
offset = 0;
}

public Figure(int theOffset)
{
offset = theOffset;
}

public void setOffset(int newOffset)
{
offset = newOffset;
}

public int getOffset()
{
return offset;
}

public void drawAt(int lineNumber)
{
int count;
for (count = 0; count < lineNumber; count++)
System.out.println();
drawHere();
}

public void drawHere()
{
int count;
for (count = 0; count < offset; count++)
System.out.println(' ');
System.out.println('*');
}
}

fizkiz07 said...

The arrow did not post right, but hopefully you understand what i was trying to draw.

PRAVINTH G said...
This comment has been removed by the author.
PRAVINTH G said...

Hi Fizkiz i have posted the program in a new thread...
http://freejavaprograms.blogspot.com/2007/10/inheritanceoverloadingoverriding.html
plz leave your comments in that thread...

suleman zia said...

Pravinth. Email me whenever there is a posting for the blog. I dont recieve any emails :--( . Fiz We can always write programs for you but remember in real life if you want to be a software programmer learn what pravinth is doing. Ask him questions not just submitting your homework.

If you dont want to be a software programmer than no worries keep posting and we will provide you with solutions. I learned everything from Pravinth :--). Just prey for him one day his dream will come true to get hired by a big company to get a job in Java and to do something unique in java which no one else have done.

PRAVINTH G said...

Thanks sule..

micheddz said...

Mr Pravinth kindly help me to create a program that will accept a float value from 0.1 to 99.9 then count the number of tens, ones and tenths.

PRAVINTH G said...

hi micheddz,
i can't able to understand your requirements....
what do you mean by tens, ones and tenths????
explain with example....

Suleman Zia said...

Yea please post an example of your output what you are trying to accomplish. As soon as you post an example give couple of days and you will get a working output.

Suleman ZIa said...

May be something like this?

Example:

Program:Enter a floating point number?

User: 24.96

Output:

10: 2 (10 + 10 = 20 so 2 tens)
4: 1( 20 + 4 = 24 so one 4 needed)
0.90( 24+ 0.90 = 24.90)
0.6(24.90 + 0.6 = 24.96)

Is this what you are looking for even if it is please post your own example

fizkiz07 said...

thank you guys for everything and i am learing alot from your programs. even though programming is not my field of study for the future you guys are helping me better understand it.

Suleman Zia said...

Thats good fizkiz. Pravinth is the man. He is my master :--). just be passionate while learning java and trust me you will love it but at the same time you will hate it, Just be patient and seek for help if you get stuck. Anyways wellcome to Java world

fizkiz07 said...

Help please Master Pravinth, Write a program that converts 24-hour time to 12-hour time. You will define an exception class called TimeFormatException. User only has extra chance to enter a correct input.

Suleman Zia said...

can you give an example on how your output is going to look like fizkiz?

fizkiz07 said...

Please enter your time in 24 hour format.
22:00
That is
10:00 pm
Again?(yes/no)
yes
Please enter your time in 24 hour format.
13:00
That is
1:00 pm
Again?(yes/no)
Please enter your time in 24 hour format.
14:80
14:80 is not a time:
Try Again:
Please enter your time in 24 hour notation.
16:65
16:65 is not a time:
The program is now ending.

SUleman Zia said...

Fizkiz post your email address. I cn't put my code over here because of html problem. Pravinth please fix this :--(

fizkiz07 said...

fizkiz07@netzero.net

serenity said...

I need some major help. I have to write a GUI java payroll program. The requirements are as follows:
1. User interaction - via a GUI
2. All logic structures - sequence, selection and repetition
3. A user defined method
4. An event handler (key or mouse)
5. Data validation
6. Use objects and members of a class
7. Internal documentation (including comments)
8.Database or Sequential file interaction
I will receive bonus points for the following:
Array(s)
Arithmetic
Counters/accumulators
Built-in math method or random number generator

Based on this, I have to write a pseudocode, a UML Diagram, and if I use a report, a print chart. Not only do I not know how to write the program, I have no idea how to do the pseudocode. I have emailed the instructor and she doesn't respond. We are only in week 3 on chapters 5 and 6 and much of this information is covered in chapters 10 -20. Can anyone help me? I need the psuedocode tonight. HELP!!!!

kajri said...

I WANT A JAVA PROGRAM ON ATM MACHINE CONTROLING
PLZZZZZZZZZZZZZ
HELP........

kajri said...

help me by giving Java Program
on ATM Controlling Program

kajri said...

MR PRAVINTH & CHRIS
I NEED YOUR HELP IMMEDIATELY
PL. WRITE A PROGRAM FOR ME FOR ATM
MACHIME
I HAVE GOT IT IN MY PROJECT


PL IT IS URGENT

PRAVINTH G said...

Hi Kajiri,
What do you mean by ATM Machine controller?. you please explain it with sample input and output.

kajri said...

Thanx Mr. PRAVINTH G actually
I want a program on Bbank ATM:

INPUT:
1. AMOUNT TO BE WITHDRWAL
2. DENOMINATION OF NOTE
SAY TOTAL WITHDRAWL-5000/-
DENOMINATION: 500/- X 2=1000/-
BALANCE WDRL. WILL BE 5000/- - 1000/-=4000/-
DENOMINATION: 100/- X 10=1000/-
BALANCE WDRL. WILL BE 4000/- -1000/-=3000/-
DENOMINATION: 50/- X 60=3000/-
BALANCE WDRL. WILL BE 5000/- -5000/-=0

OUTPUT
TOTAL WITHDRWAL WITH DENOMINATION


PL. DO IT FOR ME .
I WILL BE GREATFUL TO U

PRAVINTH G said...

Now in office mail you the program tonight from my room..

kajri said...

thanks mr pravinth



regards

kajri

PRAVINTH G said...

Hi kajiri,
I posted the program in a new thread.

DEEPALI said...

i did not get the prograb yet




pl....

DEEPALI said...

i did not get that program yet


pl will send it in my mail id kajrimukherjee@gmail.com



do rply...
regards

kajri said...

pl
send
the program in
kajrimukherjee@gmail.com.

PRAVINTH G said...

http://freejavaprograms.blogspot.com/2008/06/for-kajiri.html

kajri said...

from KAJRI

To MR. PRAVINTH
YOUR PROG. ON MY REQUEST REGARDING ATM

I HAVE COMPILED IT BUT FIND ERROR

PL CHECK THIS FOR ME

Scanner scan = new Scanner System.in);




REGARDS


KAJRI

PRAVINTH G said...

It is:
Scanner scan = new Scanner(System.in);
Whats the error it is showing-compile time error?
java.util.Scanner is available from jdk 1.5 (java 5). what version of java are you using? [you need minimum java 5 (or the latest java 6)]

Anonymous said...

Hi Chris
Could you please align the coding for the car in columns and also use StringTokenizer,modulus 11 and display it using console menu.

Anonymous said...

Mr Prvinth I am new to java I am currently a student and I really need your help with these programs. I would love to get your help but I would like to send you my class syllabus if possible but I would like to now where I need to send it to. My email address is student_1980k@yahoo.com.

domain said...

I need help!

domain said...

Please email me at jonathank1234@live.com... im stressing out way to much thanks again. hope you still check this

CzechG said...

Mr. Prvinth, I was wondering if you can help me with the following program.
I need to create inventory report. File with the data about inventory will be loaded into 7 vectors. I need to display menu option for Order, Sell, Check item, and also to print inventory report. Can you give me a hand and show me maybe with 2 vectors, because honestly I have no idea how to load data in and how to process them in methods (like sell or order). If you need more info my address is georgejirik@yahoo.com Thanks a million

Suleman Zia said...

Czechg can you give a little demo on the output on how it is suppose to look like ?

Anonymous said...

I need an urgent answer please.

Here`s the question..
Java using arrays

Write a program to input a possibly integer n(n<=10); followed by n real values into an arrya a of size n and the program must perform the following:

Display back the values input
Sort the values and display them
Display the max value
Calculate and display the average.

Anonymous said...

hi PRAVINTH G
i've got an assignment..
i'm really hard up in arriving with the correct answer,,whaa..
pls help me..
i would be very grateful.

The problem goes this way.
you only have 3 trials to input the correct pincode for a sim card..
if you inputted the wrong pin code you will be asked a PUK secret code.
if you failed to input the correct PUK secret code.
the output will be "simcard blocked"

PRAVINTH G said...

import java.io.*;
import java.util.*;

public class MaxSimTry{
MaxSimTry(){
int MaxTrials = 3;
String correctPincode = "simpass";
String correctPUK ="pukpass";

Scanner scan = new Scanner(System.in);
while(MaxTrials-->0){
System.out.print("Please Enter the correct pincode:");
String enteredPincode = scan.next();
if(enteredPincode.equals(correctPincode)){
System.out.println("Correct Pincode, sim unlocked");
return;
}
System.out.println("Wrong Pincode");
}
System.out.print("Please Enter the correct PUK:");
String enteredPUK = scan.next();
if(!enteredPUK.equals(correctPUK))
System.out.println("Simcard Blocked");
else
System.out.println("PUK is correct");
}
public static void main(String[] args){
new MaxSimTry();
}
}

kajri said...

pl. write a program for me in c & c++
for MATRIX OPERATION USING POINTER




REGRADS

PRAVINTH G said...

Hi Kajiri,
i will write atleast one sample by tomorrow. If you need more programs then give us your mail id.

PRAVINTH G said...

Hi Kajiri,
posted one program in the other thread.
https://www.blogger.com/comment.g?blogID=5133484865049964130&postID=6195818591792476540

allanmwas said...

Hi guys,just introduced to this site by a friend. Am a first year student in Kenya (JKUAT) taking comp science and would like to know how to create a java application say a sales management system or any other system using MySQl database or SQL server 2000.
If possible please send me an amarture system meeting the specifications given and necessary comments on the same.
my email: allanmwas@gmail.com
Thanks!

PRAVINTH G said...

Hi allanmwas,
First you should know mySQL/SQl Server, then you need the driver, which is required to connect to the respective database. If you want to develope a desktop application then you should learn java swing. google, you can find lot of tutorials and code samples. Here is one:
http://www.developer.com/java/data/article.php/3417381

Suleman Zia said...

Looking good

Suleman Zia said...

We started this site as a small site and now it's growing and growing. Sorry Could not come to the site as i am very very busy at work.

So who needs help and what kind of help you guys need ? If anyone have any programs or a web page developed in Spring or struts framework feel free to ask questions or any homework questions and i will be able to knock it out on the weekend as this is the only time i have :--).

Suleman Zia said...

Always good to see you Mr Pravinth My old time friend :--)

blue said...

i need a java program for computer merchandise
its urgent

PRAVINTH G said...

Hi Blue,
Added one sample for you.
Please check the below thread.
http://freejavaprograms.blogspot.com/2009/06/sample-computer-merchandise-program-for.html

blue said...

i am waiting for the computer merchandize program.

sandha said...

hi pravinth,iam preeti i have just seen ur scraps....you were helping people a lot....great job.can you help me....i have a interview with in 2 days so i need program in java where i can impress them with my program.
my frd said we can write a program like we can not open the calculater of other client without der permission....like some special program where it is not so tuff to understand...hope you help me......

PRAVINTH G said...

Hi Preethi(Sandha),
Hope you did well in your interview. we were busy with our work thats y could not able to come here. you can share ur interview experiences here..

sandha said...

hi pravinth.i did not attend interview since i heard that they were asking only java programs.actually i am from electronic background so i thought i have to prepare for that.can you say me which course will help me in fetching a job.i want to know whether we can able to write programs on servlets,swings by preparing frm home..

PRAVINTH G said...

Hi Preethi(Sandha),
wots ur e-mail id?

blue said...

Hello mr. pravinth .I hope you remember abt computer merchandise prg.

PRAVINTH G said...

Blue, give me ur email id

blue said...

nabs.teenstar@gmail.com

kajri said...

PL WRITE FEW PROG IN JAVA FOR ME
1.PATTERN
*
*
*****
*
*
2. PALINPRIME NO.

3. LONGEST PERFECT NO


REGARDS KAJRI

soumya said...

my email id is soumya.26787@gmail.com.hope you give me secessions n write a program which i asked u earlier.

PRAVINTH G said...

Hi Kajiri,
Q1) Pattern - do you mean pattern matching?
Q2) Palinprime no. - do you mean palindrome or prime no.?
Q3) Longest perfect no - give me time to do it.

PRAVINTH G said...

Hi guys, This thread has grown too big. so please post your queries/comments in the other thread - here is the link: http://freejavaprograms.blogspot.com/2009/07/plz-post-you-queries-here.html
Many Thanks !

kajri said...

pl write a program for me


......
WAP TO REVERSE A STRING IN ALPHATICAL ORDER



REGARDS
KAJRI

Anonymous said...

Hi Mr Pravinth i have to write a program for class which should ask for a mark and the student's name ,you must keep asking for the data once the mark is not -1 find the average mark,the name of the student with the hightest and the mark, the name of the student with the lowest and the mark,and the number of students in the class
Thanks in advance.

Anonymous said...

Hi Mr Pravinth..... I need to submit this java assignment question within this week and please help me..Write a function Model-of-Category for a Tata motor dealers, which accepts category of car customer is looking for and returns the car Model available in that category. the function should accept the following categories "SUV", "SEDAN", "ECONOMY", and "MINI" which in turn returns "TATA SAFARI" , "TATA INDIGO" , "TATA INDICA" and "TATA NANO" respectively.

marianmagnifico said...

hi. I'm a computer programming student freshman. we have a project point of sale system. Not the data base. Just need to compile it in console.i made a source code and it run but our instructor said something missing...can you help me to revise it? the output must show the items ordered and the quantity and also the total amount.thank you very much...god bless.

marianmagnifico said...

continuation:
import java.io.*;
import java.util.Scanner;

public class show{

public static void dMain()throws Exception{
for(int o=0;o<80;o++)
System.out.print(":");
System.out.println();
System.out.println("\t\t\tI L o v e S i o m a i !!");
for(int o=0;o<80;o++)
System.out.print(":");
System.out.println();
}
static void Option()throws Exception{
for(int o=0;o<80;o++)
System.out.print("_");
System.out.println();
System.out.println("\t\t\t\tMenu:: ");
System.out.println();
System.out.println();
System.out.println("\t\t\tSiomai");
System.out.println();
System.out.println("\t\t01 Beef siomai P 5.00 / pcs");
System.out.println("\t\t02 Pork siomai P 5.00 / pcs");
System.out.println("\t\t03 Shrimp siomai P 5.00 / pcs");
System.out.println();
System.out.println("\t\t\tSiopao");
System.out.println();
System.out.println("\t\t04 Toasted siopao P 10.00 / pcs");
System.out.println("\t\t05 Steam siopao P 10.00 / pcs");
System.out.println("\t\t06 Ube siopao P 12.00 / pcs");
System.out.println("\t\t07 Cheese siopao P 12.00 / pcs");
System.out.println("\t\t08 Choco siopao P 12.00 / pcs");
System.out.println("\t\t09 Bola bola Siopao P 12.00 / pcs");
System.out.println();
System.out.println("\t\t\tdrinks");
System.out.println();
System.out.println("\t\t10 bottled water P 15.00 / 500ml");
System.out.println("\t\t11 Coca cola P 30.00 / in can");
System.out.println("\t\t12 iceTea juice P 12.00 / pcs");
System.out.println("\t\t13 Popcola P 17.00 / 1 liter ");
System.out.println("\t\t14 Popcola P 12.00 / 12 oz");
System.out.println("\t\t15 Popcola P 6.00 / 8 oz");
System.out.println();
}

PRAVINTH G said...

Hi Marian,
First u include th call to Option() inside ur main. Then i couldn't able to understand your requirement clearly. do u want to display the options to the user? and he has to select the item?-then where is the item code?. please give a detailed description.its a simple one only.

ARLENE said...

hi!!we are ask to create an Automated Teller Machine program using java. these are the terms we have to inlude in our case study
1. InputStreamReader and BufferedReader
2. while statement
3. do-while statement
4. try-catch (exception handling)and also
attributes/behaviors, Java beans, inheritance, abstract
classes, interfaces.
the program is asking for the name and the password of the user. hope you can help me!thank you

ARLENE said...

sorry I forgot, It should first ask what is the language desired by the user by choosing a number. 1 for english and 2 for other language. please help me!!thank you very much!

Anonymous said...

Hi, I need help in JAVA programm.I totally new in JAVA.Example of the program output is given below:
OneWorld Auto Rental Sdn Bhd.
Plese enter day/s: 3
Plese enter promotional discount (%): 2
Day rental: 3day/s
Total payment: RM5880.0
Year model: 2010
Make: Nissan
Plate number: WWW 2011

email: shracc74@yahoo.com
tq.

Anonymous said...

Hi Mr. Pravinth this is my assignment: Using an array, Write a program that will do the following:

Display a menu containing the following items:
Enter students
Search student
Insert student
Delete student
Display students
Exit

User can choose the number of the menu item. When item is selected, perform the corresponding operation for that item.
Hope you can help me on these and explain also the output. Thank u very much.

Anonymous said...

Hi,

The question I have to answer is:

The IfMinMax class finds the maximum and minimum for String and int data values using if statements. Complete the methods in the IfMinMax class. Test IfMinMax class with IfMinMaxTest. IfMinMaxTest also uses CountErrors.

And the class is already started. I have to complete the methods. The class is:

public class IfMinMax{

/*
* Use an if-else statement to return the minimum in
* lexicographical order of a or b.
*/
public static String min( String a, String b ) {

}

/*
* Use two IfMinMax.min(String a, String b )
* to return the minimum of a, b, or c.
*/
public static String min( String a, String b, String c ) {
IfMinMax.min(String a, String b)
}

/*
* Use an if-else statements to return the minimum in
* lexicographical order of a, b, or c.
*/
public static String min_if( String a, String b, String c ) {
// FIX-ME
}

/*
* Use an if-else statements to return the maximum of
* a, b, c, and d. Use the smallest number of if-else
* statements.
*/
public static int max_if( int a, int b, int c, int d ){
// FIX-ME
}

/*
* Use Math.max to return the maximum of
* a, b, c, or d.
*/
public static int max( int a, int b, int c, int d ){
// FIX-ME
}
}

aeon said...
This comment has been removed by the author.
Angel10290 said...

I need help with the same program as fizkiz07

Anonymous said...

I need some help this is about C# I am a beginner so I just don't know what to do. In this case, We are only allowed to use console application since we are all beginners in C#. Here is the problem:

Write a program that displays an equivalent color once an inputted letter matches it's first character and display this:

letter color
'R' or 'r' Red
'G' or 'g' Green
'B' or 'b' Blue
other letters Unknown color

gelai cxen said...

hi im gelai
i need your help for my assignment
in java (Method)

1.Write a program that would test the age of user if he is young or old(if age is greater than 20 then the user is old) using a Method

Im just beginner in this thing so pls. help me

thanks