Assignment Due TODAY - NEED HELP
My program is below and I have already setup a Client Server Connection for a hangman game, but I need help sending and displaying the options selected by the user. PLEASE HELP
import java.io.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ClientApp extends JFrame
// Declarations used in program
private Socket server;
ObjectOutputStream out;
ObjectInputStream in;
int length = 0; // Length of word received by Server
String guess;
String lines;
String secret;
int chances = 0; // Count to Hold no of chances by user
int categorySelected ;
// GUI Declarations
private JButton btnMovies;
private JButton btnSport;
private JButton btnExit, btnNew;
private JButton a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
private JLabel lblWelcome, lblCategory , lblChances;
private JPanel pan1, pan2, pan3, pan4, pan5, pan6, pan7, pan8, pan9, pan10;
private JTextArea answer;
private JTextField txtCategory, txtChances;
// CONSTRUCTOR
public ClientApp()
setLayout(new FlowLayout());
pan1 = new JPanel();
pan3 = new JPanel();
pan2 = new JPanel();
lblWelcome = new JLabel("Welcome to Hangman.\n\n Please select a category.");
pan1.add(lblWelcome);
btnMovies = new JButton("Movie Titles");
pan3.add(btnMovies);
btnSport = new JButton("Sport");
pan3.add(btnSport);
btnNew = new JButton("New Game");
pan3.add(btnNew);
btnExit = new JButton("Exit");
pan2.add(btnExit);
pan9 = new JPanel();
txtCategory = new JTextField(10);
pan9.add(txtCategory);
pan8 = new JPanel();
answer = new JTextArea(3,30);
answer.setEditable(false);
pan8.add(answer);
add(pan1);
add(pan3);
add(pan2);
add(pan9);
add(pan8);
btnExit.addActionListener(
new ActionListener()
public void actionPerformed(ActionEvent event)
System.exit(0);
btnMovies.addActionListener(
new ActionListener()
public void actionPerformed(ActionEvent event)
enableButtons();
btnSport.setEnabled(false);
btnNew.setEnabled(true);
txtCategory.setText("Movies");
categorySelected = 0;
processClient();
btnSport.addActionListener(
new ActionListener()
public void actionPerformed(ActionEvent event)
enableButtons();
btnMovies.setEnabled(false);
btnSport.setEnabled(false);
btnNew.setEnabled(true);
txtCategory.setText("Actors Names");
categorySelected = 1;
processClient();
btnNew.addActionListener(
new ActionListener()
public void actionPerformed(ActionEvent event)
enableButtons();
btnSport.setEnabled(true);
btnMovies.setEnabled(true);
btnNew.setEnabled(false);
chances = 0;
communicate();
buttons();
disableButtons();
btnNew.setEnabled(false);
// Attempt to establish connection to server
try
// Create socket
server = new Socket("localhost", 8008);
catch (IOException ioe)
System.out.println("IOException: " + ioe.getMessage());
// Method to add Alphabetic Buttons to GUI
public void buttons()
pan4 = new JPanel();
pan5 = new JPanel();
pan6 = new JPanel();
pan7 = new JPanel();
a = new JButton("A");
b = new JButton("B");
c = new JButton("C");
d = new JButton("D");
e = new JButton("E");
f = new JButton("F");
g = new JButton("G");
h = new JButton("H");
i = new JButton("I");
j = new JButton("J");
k = new JButton("K");
l = new JButton("L");
m = new JButton("M");
n = new JButton("N");
o = new JButton("O");
p = new JButton("P");
q = new JButton("Q");
r = new JButton("R");
s = new JButton("S");
t = new JButton("T");
u = new JButton("U");
v = new JButton("V");
w = new JButton("W");
x = new JButton("X");
y = new JButton("Y");
z = new JButton("Z");
pan4.add(a);
pan4.add(b);
pan4.add(c);
pan4.add(d);
pan4.add(e);
pan4.add(f);
pan5.add(g);
pan5.add(h);
pan5.add(i);
pan5.add(j);
pan5.add(k);
pan5.add(l);
pan6.add(m);
pan6.add(n);
pan6.add(o);
pan6.add(p);
pan6.add(q);
pan6.add(r);
pan7.add(s);
pan7.add(t);
pan7.add(u);
pan7.add(v);
pan7.add(w);
pan7.add(x);
pan7.add(y);
pan7.add(z);
add(pan4);
add(pan5);
add(pan6);
add(pan7);
// Button Handler for Alphabet
ButtonHandler handler = new ButtonHandler();
a.addActionListener(handler);
b.addActionListener(handler);
c.addActionListener(handler);
d.addActionListener(handler);
e.addActionListener(handler);
f.addActionListener(handler);
g.addActionListener(handler);
h.addActionListener(handler);
i.addActionListener(handler);
j.addActionListener(handler);
k.addActionListener(handler);
l.addActionListener(handler);
m.addActionListener(handler);
n.addActionListener(handler);
o.addActionListener(handler);
p.addActionListener(handler);
q.addActionListener(handler);
r.addActionListener(handler);
s.addActionListener(handler);
t.addActionListener(handler);
u.addActionListener(handler);
v.addActionListener(handler);
w.addActionListener(handler);
x.addActionListener(handler);
y.addActionListener(handler);
z.addActionListener(handler);
private class ButtonHandler implements ActionListener
public void actionPerformed(ActionEvent ae)
if (ae.getSource()==a)
guess = "a";
a.setEnabled(false);
sendGuess();
if (ae.getSource()==b)
guess = "b";
b.setEnabled(false);
sendGuess();
if (ae.getSource()==c)
guess = "c";
c.setEnabled(false);
sendGuess();
if (ae.getSource()==d)
guess = "d";
d.setEnabled(false);
sendGuess();
if (ae.getSource()==e)
guess = "e";
e.setEnabled(false);
sendGuess();
if (ae.getSource()==f)
guess = "f";
f.setEnabled(false);
sendGuess();
if (ae.getSource()==g)
guess = "g";
g.setEnabled(false);
sendGuess();
if (ae.getSource()==h)
guess = "h";
h.setEnabled(false);
sendGuess();
if (ae.getSource()==i)
guess = "i";
i.setEnabled(false);
sendGuess();
if (ae.getSource()==j)
guess = "j";
j.setEnabled(false);
sendGuess();
if (ae.getSource()==k)
guess = "k";
k.setEnabled(false);
sendGuess();
if (ae.getSource()==l)
guess = "l";
l.setEnabled(false);
sendGuess();
if (ae.getSource()==m)
guess = "m";
m.setEnabled(false);
sendGuess();
if (ae.getSource()==n)
guess = "n";
n.setEnabled(false);
sendGuess();
if (ae.getSource()==o)
guess = "o";
o.setEnabled(false);
sendGuess();
if (ae.getSource()==p)
guess = "p";
p.setEnabled(false);
sendGuess();
if (ae.getSource()==q)
guess = "q";
q.setEnabled(false);
sendGuess();
if (ae.getSource()==r)
guess = "r";
r.setEnabled(false);
sendGuess();
if (ae.getSource()==s)
guess = "s";
s.setEnabled(false);
sendGuess();
if (ae.getSource()==t)
guess = "t";
t.setEnabled(false);
sendGuess();
if (ae.getSource()==u)
guess = "u";
u.setEnabled(false);
sendGuess();
if (ae.getSource()==v)
guess = "v";
v.setEnabled(false);
sendGuess();
if (ae.getSource()==w)
guess = "w";
w.setEnabled(false);
sendGuess();
if (ae.getSource()==x)
guess = "x";
x.setEnabled(false);
sendGuess();
if (ae.getSource()==y)
guess = "y";
y.setEnabled(false);
sendGuess();
if (ae.getSource()==z)
guess = "z";
z.setEnabled(false);
sendGuess();
// Method to Disable the buttons
public void disableButtons()
a.setEnabled(false);
b.setEnabled(false);
c.setEnabled(false);
d.setEnabled(false);
e.setEnabled(false);
f.setEnabled(false);
g.setEnabled(false);
h.setEnabled(false);
i.setEnabled(false);
j.setEnabled(false);
k.setEnabled(false);
l.setEnabled(false);
m.setEnabled(false);
n.setEnabled(false);
o.setEnabled(false);
p.setEnabled(false);
q.setEnabled(false);
r.setEnabled(false);
s.setEnabled(false);
t.setEnabled(false);
u.setEnabled(false);
v.setEnabled(false);
w.setEnabled(false);
x.setEnabled(false);
y.setEnabled(false);
z.setEnabled(false);
// Method to enable Buttons so user can Click on them
public void enableButtons()
a.setEnabled(true);
b.setEnabled(true);
c.setEnabled(true);
d.setEnabled(true);
e.setEnabled(true);
f.setEnabled(true);
g.setEnabled(true);
h.setEnabled(true);
i.setEnabled(true);
j.setEnabled(true);
k.setEnabled(true);
l.setEnabled(true);
m.setEnabled(true);
n.setEnabled(true);
o.setEnabled(true);
p.setEnabled(true);
q.setEnabled(true);
r.setEnabled(true);
s.setEnabled(true);
t.setEnabled(true);
u.setEnabled(true);
v.setEnabled(true);
w.setEnabled(true);
x.setEnabled(true);
y.setEnabled(true);
z.setEnabled(true);
public void communicate()
// The connection has been established - now send/receive.
try
// create channels
out = new ObjectOutputStream(server.getOutputStream());
out.flush();
in = new ObjectInputStream(server.getInputStream());
catch (IOException ioe)
JOptionPane.showMessageDialog(null,"IO Exception: " + ioe.getMessage());
catch (NullPointerException n)
JOptionPane.showMessageDialog(null,"Error occured...");
public void processClient()
try
// Tells server which category is selected by user
out.writeObject(categorySelected);
out.flush();
secret = (String)in.readObject();
length = (Integer)in.readObject();
lines = "";
for (int x=0;x < length;x++)
lines += " - ";
answer.setText(lines);
String ToDisplay="";
for (int q=0; q<secret.length;q++)
ToDisplay+=secret.length;
answer.setText(" " + ToDisplay); */
// String Correctin = (String)in.readObject();
// JOptionPane.showMessageDialog(null, Correctin );
catch (IOException ioe)
JOptionPane.showMessageDialog(null, "IO Exception: " + ioe.getMessage());
catch (ClassNotFoundException cnfe)
JOptionPane.showMessageDialog(null, "Class not found..." );
}//end method
public void sendGuess()
try
// Sends the character guessed by user
out.writeObject(guess);
out.flush();
// Chances incremented
//chances = chances + 1;
// Calcualates to see whether chances are up
//if (chances >= 7)
// JOptionPane.showMessageDialog(null,"GAME OVER!! You used up all your chances...");
// disableButtons();
}//end try
catch (IOException ioe)
JOptionPane.showMessageDialog(null, ioe.getMessage());
}//end catch
}//end method
public static void main(String[] args)
ClientApp client = new ClientApp();
client.communicate();
client.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
client.setSize(500,300);
client.setVisible(true);
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
public class ServerApp
String movies [] = {"shrek","titanic","disturbia","blade","scream"};
String sport [] = {"tennis","golf","rugby","hockey","soccer","judo"};
int inCategory; // Category Selected By User
int selectw; // Random word selected in Array
String secretword = "";
int wordlength = 0;
String guess;
char letter;
Random rand = new Random();
String msg;
ObjectOutputStream out;
ObjectInputStream in;
int chances;
// Server socket
private ServerSocket listener;
// Client connection
private Socket client;
public ServerApp()
// Create server socket
try {
listener = new ServerSocket(8008);
catch (IOException ioe)
JOptionPane.showMessageDialog(null,"IO Exception: " + ioe.getMessage());
public void listen()
// Start listening for client connections
try
client = listener.accept();
System.out.println("Server started");
processClient();
}//end try
catch(IOException ioe)
JOptionPane.showMessageDialog(null,"IO Exception: " + ioe.getMessage());
}//end catch
public void processClient()
try
while(msg != "TERMINATE")
//input and output stream
out = new ObjectOutputStream(client.getOutputStream());
out.flush();
in = new ObjectInputStream(client.getInputStream());
//Receiving a category
inCategory = (Integer)in.readObject();
chances = 7;
selectw = 0;
if (inCategory == 0)
selectw = rand.nextInt(5);
secretword = movies[selectw];
out.writeObject(secretword);
out.flush();
}//end if
if (inCategory == 1)
selectw = rand.nextInt(6);
secretword = sport[selectw];
}//end if
wordlength = secretword.length();
out.writeObject(wordlength);
out.flush();
for (int y=0;y < wordlength;y++)
guess = (String)in.readObject();
letter = guess.charAt(0);
if(chances == 0)
JOptionPane.showMessageDialog(null,"No more chances left");
else
if(letter == secretword.charAt(y))
JOptionPane.showMessageDialog(null,"You chose a correct letter...");
else
JOptionPane.showMessageDialog(null,"You chose a wrong letter...");
chances--;
JOptionPane.showMessageDialog(null,"You won the game...");
}//end while
// Step 3:close down
out.close();
in.close();
client.close();
System.out.println("Server stopped");
catch (IOException ioe)
JOptionPane.showMessageDialog(null,"IO Exception: " + ioe.getMessage());
catch (ClassNotFoundException cnfe)
JOptionPane.showMessageDialog(null,"Class not found: " + cnfe.getMessage());
public static void main(String[] args)
// Create application
ServerApp server = new ServerApp();
// Start waiting for connections
server.listen();
}
JAVAHELPNEEDED wrote:
How do I save that amount of code?
Can you HELP me or NOT??Depends what you mean. Will I write you any code? No. Will I tell you what to write? No. You can do it yourself, that's why it's called your homework. I will, though, give you a couple of tips on how to get started.
1) Throw away what you've done
2) Do a quick requirements analysis. That means, write down descriptive, plain English (or whatever language you think in) what the thing is supposed to do. "Be a hangman game" is too brief, but twenty pages of technical jargon is too much. Write a bit of a story about what the program must do. You now have the start of a design.
3) Break down what has to be done into manageable chunks. Your first mistake (and most newbs) was trying to write one side of the game in a single class. Don't be afraid to write 20 classes, or 50, if that's what's needed. It'll be easier both now and in the long run
4) Tackle each chunk one by one. Don't try and do it all at once, that never works. If you write the code one bit at a time, you'll inevitably write more modular code
5) You'll probably screw it up. Don't worry. It happens. Try again
6) Don't give up. Writing software is hard, there's no way around that, so deal with it
7) Don't make the mistake of thinking the software is the GUI. It isn't (don't extend JFrame, hint hint)
8) Good luck
Similar Messages
-
First Java Programming Assignment - Grad student needs Help
Thank-you to whomever helps me out here (I have been waiting for the Professor to respond for 2 days now, and our asignment is due by midnight 2-nite. Here is my problem. We have a value called nPer. This value is defined as a double (it needs to since, it perfoms lots of calculations). Now the assigment calls for the print line to display the field in its integer format. So I have done the following:
nPer=Math.ceil(nPer);
This has caused the value to be represented as 181.0. Not good enough! The value needs to be truncated and represented as 181.
The professor has provided us with directions that use the following syntax
(int)181.0
Putting that exact code in my program causes JBuilder to create an error message. Ergo, its not right. I have serached all over the tutorial looking for the proper method to resolve this, however - no luck. Could some kind sole please help??? Thank-you.You can look at either java.math.BigDecimal, if the
true representation of the value and rounding are a
concern, or java.text.NumberFormat if it's simply a
matter of display.
Your professor must be an old C programmer. Casting a
double to an int? Oh, my. - MODBut that's what his assignment says, display it as an int. And the cast would work; I'm assuming he just didn't use it right. -
SharePoint View - 3pm yesterday to 3pm Today - Need Help
Hello All,
I have a basic requirement to show "Daily" stats on a list. Criteria are 3pm yesterday to 3pm today due to hard cut off submissions.
In researching, I took action by modifying a view on (Created Date) & custom calculated column that only shows hours of created date in 24-hour format. I thought I could apply a simple filter:
Created date <= [Today]-1 & [Custom Colum] <= 15 & Created date >= [Today] & [Custom colum] >= 15
Turns out it doesn't like it. Any other simple suggestions that I can apply or research to get 3pm yesterday - 3pm today filter?
I have limited SPD experience in writing code but eager to learn.
Thank you for your time, any help would be appreciatedHello,
The code I shared that was tested code for Calendar List. Please verify You may be doing anything wrong.
- Yes you need to use SPD CAML editing, because the browser based filter allow 'All' match , and we need 'Either-Or' Filters. So you will have to modify the view CAML using SPD.
- The code I have shared in my previous reply that was for Calendar list/view.I am Sharing the
Tested and verified steps again for Custom List/Tabular View and for Modified Field . Hope This will be helpful.
1- Create a Calculated column in your list. Note that should return Numeric Value for Hours ,
Not "hh:mm:ss" . So the formula should be -
Name - ModifiedHrs
Type - Calculated
Formula: =HOUR(Modified)
Format -Number (1, 1.0, 100)
Number of decimal places: 0
2- Create a Tabular View ( e.g. DayState.aspx) for your List. (not Calendar View), through browser with filter ( Modified equal to [Today]).
3. Now Open the view page (DayState.aspx) in SharePoint designer code view [Edit in Advance Mode]
4. Locate the CAML query associated with the filter (Modified = [Today]), you can find something like
<WebPartPages:WebPartZone ---
<WebPartPages:XsltListViewWebPart ----
<XmlDefinition>
<View --->
<Query>
<OrderBy>--</OrderBy>
<Where>
<Eq>
<FieldRef Name="Modified"/>
<Value Type="DateTime"><Today/></Value>
</Eq>
</Where>
</Query>
<ViewFields---->
</View></XmlDefinition>
</XmlDefinition>
5. Replace the <Where>----</Where> Section with this one
<Where>
<Or><And><Eq><FieldRef Name="Modified"/>
<Value Type="DateTime"><Today OffsetDays="-1"/>
</Value></Eq><Gt><FieldRef Name="ModifiedHrs"/>
<Value Type="Number">14</Value></Gt></And>
<And><Eq><FieldRef Name="Modified"/>
<Value Type="DateTime"><Today/></Value></Eq><Lt>
<FieldRef Name="ModifiedHrs"/>
<Value Type="Number">16</Value></Lt></And></Or>
</Where>
6. Save the page , and test it in browser
7. Note :
If you have different field names , then Please change the field names with InternalName of fields in your List
Set the CAML in single line , remove spaces
This is for Custom List/Tabular View. For Calendar view , the View Definition are in different format, you will have to replace < and > as I explained in my previous post.
This is tested code , so it should work. In Case of any issue , you can PM/email me or Post here.Thanks
Thanks
Ganesh Jat [My Blog |
LinkedIn | Twitter ]
Please click 'Mark As Answer' if a post solves your problem or 'Vote As Helpful' if it was useful.
Hello Ganesh,
Had time today and updated. Something was off (not related) on my old view and so decided to start from scratch.
Thank you for your help & very helpful workthrough post. This is working 100%.
I have two more ideas that i'm working on, would you mind if I reach out to you? -
Just downloaded SQL Developer today, need help copy data
How do I import data from Oracle XE to an Oracle server by using SQL Developer?
Probably a better option would be use the export and import utilities provided with the database.
From within SQL*Developer you can export data as either a csv file (and then use sql*loader to load it), or as insert statements which you can run in in either sql*developer or sql*plus.
To export data in sql*developer, right-click on a table or a result set.
Search for Export Table Data in the help system -
Need help with calculator project for an assignment...
Hi all, I please need help with my calculator project that I have to do for an assignment.
Here is the project's specifications that I need to do"
"""Create a console calculator applicaion that:
* Takes one command line argument: your name and surname. When the
program starts, display the date and time with a welcome message for the
user.
* Display all the available options to the user. Your calculator must include
the arithmetic operations as well as at least five scientific operations of the
Math class.
-Your program must also have the ability to round a number and
truncate it.
-When you multiply by 2, you should not use the '*' operator to perform the
operation.
-Your program must also be able to reverse the sign of a number.
* Include sufficient error checking in your program to ensure that the user
only enters valid input. Make use of the String; Character, and other
wrapper classes to help you.
* Your program must be able to do conversions between decimal, octal and
hex numbers.
* Make use of a menu. You should give the user the option to end the
program when entering a certain option.
* When the program exits, display a message for the user, stating the
current time, and calculate and display how long the user used your
program.
* Make use of helper classes where possible.
* Use the SDK to run your program."""
When the program starts, it asks the user for his/her name and surname. I got the program to ask the user again and again for his/her name and surname
when he/she doesn't insert anything or just press 'enter', but if the user enters a number for the name and surname part, the program continues.
Now my question is this: How can I restrict the user to only enter 'letters' (and spaces of course) but allow NO numbers for his/her surname??
Here is the programs code that I've written so far:
{code}
import java.io.*;
import java.util.*;
import java.text.*;
public class Project {
private static String nameSurname = "";
private static String num1 = null;
private static String num2 = null;
private static String choice1 = null;
private static double answer = 0;
private static String more;
public double Add() {
answer = (Double.parseDouble(num1) + Double.parseDouble(num2));
return answer;
public double Subtract() {
answer = (Double.parseDouble(num1) - Double.parseDouble(num2));
return answer;
public double Multiply() {
answer = (Double.parseDouble(num1) * Double.parseDouble(num2));
return answer;
public double Divide() {
answer = (Double.parseDouble(num1) / Double.parseDouble(num2));
return answer;
public double Modulus() {
answer = (Double.parseDouble(num1) % Double.parseDouble(num2));
return answer;
public double maximumValue() {
answer = (Math.max(Double.parseDouble(num1), Double.parseDouble(num2)));
return answer;
public double minimumValue() {
answer = (Math.min(Double.parseDouble(num1), Double.parseDouble(num2)));
return answer;
public double absoluteNumber1() {
answer = (Math.abs(Double.parseDouble(num1)));
return answer;
public double absoluteNumber2() {
answer = (Math.abs(Double.parseDouble(num2)));
return answer;
public double Squareroot1() {
answer = (Math.sqrt(Double.parseDouble(num1)));
return answer;
public double Squareroot2() {
answer = (Math.sqrt(Double.parseDouble(num2)));
return answer;
public static String octalEquivalent1() {
int iNum1 = Integer.parseInt(num1);
String octal1 = Integer.toOctalString(iNum1);
return octal1;
public static String octalEquivalent2() {
int iNum2 = Integer.parseInt(num2);
String octal2 = Integer.toOctalString(iNum2);
return octal2;
public static String hexadecimalEquivalent1() {
int iNum1 = Integer.parseInt(num1);
String hex1 = Integer.toHexString(iNum1);
return hex1;
public static String hexadecimalEquivalent2() {
int iNum2 = Integer.parseInt(num2);
String hex2 = Integer.toHexString(iNum2);
return hex2;
public double Round1() {
answer = Math.round(Double.parseDouble(num1));
return answer;
public double Round2() {
answer = Math.round(Double.parseDouble(num2));
return answer;
SimpleDateFormat format1 = new SimpleDateFormat("EEEE, dd MMMM yyyy");
Date now = new Date();
SimpleDateFormat format2 = new SimpleDateFormat("hh:mm a");
static Date timeIn = new Date();
public static long programRuntime() {
Date timeInD = timeIn;
long timeOutD = System.currentTimeMillis();
long msec = timeOutD - timeInD.getTime();
float timeHours = msec / 1000;
return (long) timeHours;
DecimalFormat decimals = new DecimalFormat("#0.00");
public String insertNameAndSurname() throws IOException{
boolean inputCorrect = false;
while (inputCorrect == false) {
while (nameSurname == null || nameSurname.length() == 0) {
for (int i = 0; i < nameSurname.length(); i++) {
if ((nameSurname.charAt(i) > 'a') && (nameSurname.charAt(i) < 'Z')){
inputCorrect = true;
else{
inputCorrect = false;
break;
try {
BufferedReader inStream = new BufferedReader (new InputStreamReader(System.in));
System.out.print("Please enter your name and surname: ");
nameSurname = inStream.readLine();
inputCorrect = true;
}catch (IOException ex) {
System.out.println("You did not enter your name and surname, " + nameSurname + " is not a name, please enter your name and surname :");
inputCorrect = false;
System.out.println("\nA warm welcome " + nameSurname + " ,todays date is: " + format1.format(now));
System.out.println("and the time is now exactly " + format2.format(timeIn) + ".");
return nameSurname;
public String inputNumber1() throws IOException {
boolean inputCorrect = false;
while (inputCorrect == false) {
try {
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
System.out.print("\nPlease enter a number you want to do a calculation with and hit <ENTER>: ");
num1 = br.readLine();
double number1 = Double.parseDouble(num1);
System.out.println("\nThe number you have entered is: " + number1);
inputCorrect = true;
} catch (NumberFormatException nfe) {
System.out.println("\nYou did not enter a valid number: " + "\""+ num1 + "\" is not a number!!");
inputCorrect = false;
return num1;
public String calculatorChoice() throws IOException {
System.out.println("Please select an option of what you would like to do with this number from the menu below and hit <ENTER>: ");
System.out.println("\n*********************************************");
System.out.println("---------------------------------------------");
System.out.println("Please select an option from the list below: ");
System.out.println("---------------------------------------------");
System.out.println("1 - Add");
System.out.println("2 - Subtract");
System.out.println("3 - Multiply");
System.out.println("4 - Divide (remainder included)");
System.out.println("5 - Maximum and minimum value of two numbers");
System.out.println("6 - Squareroot");
System.out.println("7 - Absolute value of numbers");
System.out.println("8 - Octal and Hexadecimal equivalent of numbers");
System.out.println("9 - Round numbers");
System.out.println("0 - Exit program");
System.out.println("**********************************************");
boolean inputCorrect = false;
while (inputCorrect == false) {
try {
BufferedReader inStream = new BufferedReader (new InputStreamReader(System.in));
System.out.print("Please enter your option and hit <ENTER>: ");
choice1 = inStream.readLine();
int c1 = Integer.parseInt(choice1);
System.out.println("\nYou have entered choice number: " + c1);
inputCorrect = true;
} catch (NumberFormatException nfe) {
System.out.println("You did not enter a valid choice number: " + "\""+ choice1 + "\" is not in the list!!");
inputCorrect = false;
return choice1;
public String inputNumber2() throws IOException {
boolean inputCorrect = false;
while (inputCorrect == false) {
try {
BufferedReader br2 = new BufferedReader (new InputStreamReader(System.in));
System.out.print("\nPlease enter another number you want to do the calculation with and hit <ENTER>: ");
num2 = br2.readLine();
double n2 = Double.parseDouble(num2);
System.out.println("\nThe second number you have entered is: " + n2);
System.out.println("\nYour numbers are: " + num1 + " and " + num2);
inputCorrect = true;
} catch (NumberFormatException nfe) {
System.out.println("You did not enter a valid number: " + "\""+ num2 + "\" is not a number!!");
inputCorrect = false;
return num2;
public int Calculator() {
int choice2 = (int) Double.parseDouble(choice1);
switch (choice2) {
case 1 :
Add();
System.out.print("The answer of " + num1 + " + " + num2 + " is: " + decimals.format(answer));
break;
case 2 :
Subtract();
System.out.print("The answer of " + num1 + " - " + num2 + " is: " + decimals.format(answer));
break;
case 3 :
Multiply();
System.out.print("The answer of " + num1 + " * " + num2 + " is: " + decimals.format(answer));
break;
case 4 :
Divide();
System.out.print("The answer of " + num1 + " / " + num2 + " is: " + decimals.format(answer));
Modulus();
System.out.print(" and the remainder is " + decimals.format(answer));
break;
case 5 :
maximumValue();
System.out.println("The maximum number between the numbers " + num1 + " and " + num2 + " is: " + decimals.format(answer));
minimumValue();
System.out.println("The minimum number between the numbers " + num1 + " and " + num2 + " is: " + decimals.format(answer));
break;
case 6 :
Squareroot1();
System.out.println("The squareroot of value " + num1 + " is: " + decimals.format(answer));
Squareroot2();
System.out.println("The squareroot of value " + num2 + " is: " + decimals.format(answer));
break;
case 7 :
absoluteNumber1();
System.out.println("The absolute number of " + num1 + " is: " + decimals.format(answer));
absoluteNumber2();
System.out.println("The absolute number of " + num2 + " is: " + decimals.format(answer));
break;
case 8 :
octalEquivalent1();
System.out.println("The octal equivalent of " + num1 + " is: " + octalEquivalent1());
octalEquivalent2();
System.out.println("The octal equivalent of " + num2 + " is: " + octalEquivalent2());
hexadecimalEquivalent1();
System.out.println("\nThe hexadecimal equivalent of " + num1 + " is: " + hexadecimalEquivalent1());
hexadecimalEquivalent2();
System.out.println("The hexadecimal equivalent of " + num2 + " is: " + hexadecimalEquivalent2());
break;
case 9 :
Round1();
System.out.println("The rounded number of " + num1 + " is: " + decimals.format(answer));
Round2();
System.out.println("The rounded number of " + num2 + " is: " + decimals.format(answer));
break;
case 0 :
if (choice2 == 0) {
System.exit(1);
break;
return choice2;
public String anotherCalculation() throws IOException {
boolean inputCorrect = false;
while (inputCorrect == false) {
try {
BufferedReader br3 = new BufferedReader (new InputStreamReader(System.in));
System.out.print("\nWould you like to do another calculation? Y/N ");
more = br3.readLine();
String s1 = "y";
String s2 = "Y";
if (more.equals(s1) || more.equals(s2)) {
inputCorrect = true;
while (inputCorrect = true){
inputNumber1();
System.out.println("");
calculatorChoice();
System.out.println("");
inputNumber2();
System.out.println("");
Calculator();
System.out.println("");
anotherCalculation();
System.out.println("");
inputCorrect = true;
} else {
System.out.println("\n" + nameSurname + " thank you for using this program, you have used this program for: " + decimals.format(programRuntime()) + " seconds");
System.out.println("the program will now exit, Goodbye.");
System.exit(0);
} catch (IOException ex){
System.out.println("You did not enter a valid answer: " + "\""+ more + "\" is not in the list!!");
inputCorrect = false;
return more;
public static void main(String[] args) throws IOException {
Project p1 = new Project();
p1.insertNameAndSurname();
System.out.println("");
p1.inputNumber1();
System.out.println("");
p1.calculatorChoice();
System.out.println("");
p1.inputNumber2();
System.out.println("");
p1.Calculator();
System.out.println("");
p1.anotherCalculation();
System.out.println("");
{code}
*Can you please run my code for yourself and have a look at how this program is constructed*
*and give me ANY feedback on how I can better this code(program) or if I've done anything wrong from your point of view.*
Your help will be much appreciated.
Thanks in advanceSmirre wrote:
Now my question is this: How can I restrict the user to only enter 'letters' (and spaces of course) but allow NO numbers for his/her surname??You cannot restrict the user. It is a sad fact in programming that the worst bug always sits in front of the Computer.
What you could do is checking the input string for numbers. If it contains numbers, just reprompt for the Name.
AND you might want to ask yourself why the heck a calculator needs to know the users Name. -
Hi! I need help, today I connected my mac Book Air to a tv for a presentation and as soon as I conected it the image on my screen went bigger. And I cant find the way to put it back as it was before. The Images are too big! heelp
Morning DeeHutton,
Thanks for using Apple Support Communities.
For more information on this, take a look at this article:
iPhone: Hardware troubleshooting
http://support.apple.com/kb/ts2802
Best of luck,
Mario -
it worked yesterday but not today and it is only a new ipod touch, it will not even be recognised on my itunes but yet it can charge off my computer. need help!
iOS: Device not recognized in iTunes for Mac OS X
or
iOS: Device not recognized in iTunes for Windows -
I cannot find my photos or contacts. Help how do I get them back after a iclound backup was done due to needed to get a new iphone. HELP
I believe I had leopard and I was having issues getting errors of system not being supported. I contacted Apple and was advised I needed to upgrade to snow leopard. My laptop is from 2009 and I haven't done anything to it till now. The apple rep also stated I should do a fresh install when putting snow leopard on so my laptop would run faster. Apple rep told me to get a external hard drive to put my info on it so the fresh install would reset everything to like it was brand new. I had someone help me with getting everything on the EHD.. doing the right format and such and then once that was done I put in the CD for snow leopard and hit install. Which brings me to now, with everything but my pictures. I have the EHD plugged in... now what? What do I do? I have looked in the EHD in iphoto and it was all standard images *not my pictures but images of a check mark or an arrow again not actual pictures. I don't see a folder pictures and i looked for images and found nothing. I have Applications, Included Free Designs, Library, System, User Guides and Information and Users, those are my options and non of those have a "pictures"
I have iPhoto '09 version 8.1.2 & Mac OS X version 10.6.3 -
Hi i need help please i been playing clash of clans over 13 months. And today o realise what someone using my game Centra. Someone playing on my game Clash of Clans. I been change my Apple ID password, email, but doesn't work. Then I playing game I can see what someone else trying connecting to my game And I don't know what to do.So if you can help me please? I don't wanna lose my game.
Contact iTunes
Contact iTunes -
Hi i need help please i been playing clash of clans over 13 months. And today o realise what someone using my game Centra. Someone playing on my game Clash of Clans. I been change my Apple ID password, email, but doesn't work. When I playing game I can see what someone else trying connecting to my game And I don't know what to do.So if you can help me please? I don't wanna lose my game.
Hello Vaidas Vaidas,
It sounds like you are noticing someone else is accessing your Clash of Clans data by playing the game and you have tried to reset your Apple ID password. If you are following the steps outlined in this article:
Apple ID: Changing your password
http://support.apple.com/kb/ht5624
What is preventing you from changing your password? Any error messages or prompts?
Thank you for using Apple Support Communities.
All the best,
Sterling -
my Creative Cloud subscription has expired, and I assigned the monthly payment, but I can not open any progam creative cloud, I need help how to solve this problem
Carlos-
Start by signing out and back in to see if it will see the subscription:
How to sign in and sign out of creative cloud (activate/deactivate)
If the apps are installed fine and close after launch see this link:
CC applications close immediately after launch
If the problem is something different, please let us know the error you see or what is happening on the screen so we can advise you on a solution
Pattie -
I have an old Itunes account from a few years ago. I want to find the music I purchased and add it to my shuffle I just bought today. Help needed please. Thanks
Robert Dauchot wrote:
I have an old Itunes account from a few years ago. I want to find the music I purchased and add it to my shuffle I just bought today.
You don't need a new iTunes account (and really shouldn't create one) simply because you purchased a new shuffle.
Continue to use the iTunes account you had.
Update your AppeID with new email address here -> Apple ID: Changing the email address you use for your Apple ID
You can downlaod previous purchases.
See this -> http://support.apple.com/kb/HT2519 -
i have final cut pro x-i have been using the share button previously and had no problem.as of today i share a movie to 720hd, and after a while it says share successful but i cannot find where the movie has been saved???need help--i cannot find the destination. can this be changed.it used to go to itunes, home video.thanks, dimitrios
EExactly what settings are you using. Some go to iTunes.
-
Need help in my assignment, Java programing?
Need help in my assignment, Java programing?
It is said that there is only one natural number n such that n-1 is a square and
n + 1 is a cube, that is, n - 1 = x2 and n + 1 = y3 for some natural numbers x and y. Please implement a program in Java.
plz help!!
and this is my code
but I don't no how to finsh it with the right condition!
plz heelp!!
and I don't know if it right or wrong!
PLZ help me!!
import javax.swing.JOptionPane;
public class eiman {
public static void main( String [] args){
String a,b;
double n,x,y,z;
boolean q= true;
boolean w= false;
a=JOptionPane.showInputDialog("Please enter a number for n");
n=Double.parseDouble(a);
System.out.println(n);
x=Math.sqrt(n-1);
y=Math.cbrt(n+1);
}OK I'll bite.
I assume that this is some kind of assignment.
What is the program supposed to do?
1. Figure out the value of N
2. Given an N determine if it is the correct value
I would expect #1, but then again this seem to be a strange programming assignment to me.
// additions followI see by the simulpostings that it is indeed #1.
So I will give the tried and true advice at the risk of copyright infringement.
get out a paper and pencil and think about how you would figure this out by hand.
The structure of a program will emerge from the mists.
Now that I think about it that advice must be in public domain by now.
Edited by: johndjr on Oct 14, 2008 3:31 PM
added additional info -
I need help!!! Did my iOS 6 update today, thought it was fine!! Then my friend text me and instead of saying Siobhain it says voicemail text message!! I've tried deleting her and adding her again, turning phone off etc etc!! Please help!!
I know of no way to remove encryption on iTunes backups if you've forgotton the password. If you've used the 4 digit PIN code to lock your iPhone in the past that can sometimes default as your "password" for this encryption in iTunes. Try that PIN or any PIN you've used in the past. If you don't use a lock maybe you played around with that feature once when you first got your phone....try "1,2,3,4" or anything you could have possibly tried.
As far as accessing older unencrypted backups you can try this software. I do not have any experience using it but it seems like it's what you need and is probably the easiest route for both voicemail and texts:
http://deciphertools.com/products.html
If you want to try to find voicemails using Terminal, I found this link as well:
http://mikereys.wordpress.com/2011/10/18/iphone-backup-restoring-visual-voice-ma il/
I know with AT&T, voicemails are only stored on their servers for 30 days so any voicemail older than that you would not have been able to access again.
Best of luck.
Maybe you are looking for
-
My music library is hiding(but still there) on my Zen 32
Hey. So for the past /2 of the year or so, I've found that my Zen was mysteriously becoming incompatible with a 3rd party app for last.fm. I never figured out why, and I assumed it was a fault in the app, since it had never been completed and was lef
-
I have safari 5.1.7 and it's not working properly. Should I use Safari 5.1.9 or 6.0.4? Mac OS X 10.6.8. 17" MacBook Pro
-
Failing to connect via HDMI port on Marantz sr7002 AV receiver.
I tested the HDMI ports with other equipment and they work fine. The Apple TV works fine when connected directly to the TV, but I need the HDMI port on the TV to connect the AV receiver. I do get the sound from the automated voice ("please connect ke
-
Hii all, how can we create a report for purchase tax register
Purchase Tax Register 2: Fields on selection screen (input screen) : Vendor Code from to , Date from to, Material Type from to, Tax Code from to . Field in the output List : Document Number , PO Number ,PO Date , Vendor C
-
Dear Oracle Support I have down load Oracle Developer Suite 10g (10.1.2.0.2) for Microsoft Windows this tow files name as the following ds_windows_x86_101202_disk1 , ds_windows_x86_101202_disk2 from this site of oracle http://www.oracle.com/technetwo