Make Program That Tells User To Type Sentence?

May 21, 2014

Ok, so I have to make a program that tells the user to type a sentence and at the end of the sentence a "." must be put to end the program. If a "." period is not entered, it must re-prompt the user to enter a period. On top of all this, the program has to count the number of letters in the sentence. I cant seem to get the while loop working and I cant find anywhere how to make a counter count the number of letters.

import java.io.*;
class Sentence
//The purpose of this program is to

[Code]....

View Replies


ADVERTISEMENT

Java Program That Tells Whether A Student Hass Passed Or Failed

Oct 21, 2014

A University offers a course that prepares students for the county licensing exam for real estate brokers. Last year, twenty students who completed this course took the exam. The university wants to know how well its students did an exam. You have been asked to write a program to summarize the results. You have been given a list of these 20 students. Next to each is written a1 if the student passed the exam or a2 if the student failed the exam.Your program should analyze the results as follows:

i.Input each test result (i.e., a1 or a2). Display the message Enter result on the screen each time the program requests another test result.
ii.Count the number of test results of each type.
iii.Display a summary of the test results, indicating the number of students who passed and the number who failed.
iv.If more than 15 students passed the exam, output message, Bonus to the instructor

View Replies View Related

Define Variable When User Has To Type Into Program So It Can Be Converted

Sep 23, 2014

I don't understand how i'm supposed to define a variable when the user has to type it into the program so it can be converted. This program i'm working on is supposed to convert from meters to feet (meter = feet * 0.305) but the user has to type in the meters they want converted. how do i solve the problem that keeps coming up that says "variable meter symbol cant be found" ? I keep trying different lines to no avail

public class Lab2
{
public static void main(String[] args) {
double feet = meter * 0.305;
double meter = feet/0.305;
System.out.println("Enter in feet for conversion to meters");
meter = meter * 0.305;

[Code] .....

View Replies View Related

Check If A Sentence From User Has Specific Letter?

May 1, 2014

I am trying to write a simple program that checks if a user's input has a specific letter using the ".contains" method but its not doing what i wanted to do. here is my code below.

import java.util.Scanner;
public class secret
{
public static void main(String args[]) {
Scanner sc;
char hidden='a';
String guess;

[Code] ....

View Replies View Related

Translate User Inputted Sentence Into MorseCode - No Output?

Feb 19, 2014

The purpose of this program is to translate a user inputed sentence into morseCode. It seems like everything is right to me, but I'm simply not getting output! What am I doing wrong, or what should I add/change?

Here is the main class:

public class MorseCode
{
public static String myInput;
public static String[] myMorse;
public static String myUserInput;
public static char[] myAlph = {'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'};
public MorseCode()

[Code] ....

View Replies View Related

Encrypt / Decrypt User Sentence Using Array And Random Encryption

Oct 28, 2014

My assignment is to write a program that will encrypt and decrypt a sentence entered by a user but the encryption is to be random using an array. Can I convert my sentence(string) from char to int then create a random array to encrypt?

import java.util.Scanner;
import java.util.Random;
/*SentenceEncryptionProgram
*/
public class SentenceEncryption {
string sentence; //sentence entered by user

[Code] ....

View Replies View Related

Requiring User To Enter Word / Sentence To Encrypt Or Decipher

Apr 10, 2014

I've been given an assignment for my Programming Fundamentals class that requires the user to enter a word/sentence to encrypt or decipher, as well as requiring the user to enter a key in which to encrpyt/decrypt the input by.

So a = no shift, b = a shift by 1 and so on.

But I'm completely lost as to what to do, and after searching for Vigenere Cipher topics, they look completely different to mine and (hardly) include prompts?This is my code:

/**
* @(#)VigenereCipher.java
*/
import java.util.Scanner;
public class VigenereCipher
{
public VigenereCipher()

[code]....

View Replies View Related

Program To Convert All Vowels To Capital Letter In A Sentence?

Jul 3, 2014

i am new to programming skills it may be silly question for experience but for me it's new thing. actually i tried a lot but i am facing problem when i trying to take input through Scanner. if i will take input a sentence directly as a string it's working . but when i am trying with Scanner the first word is showing next are not showing

public class Demo2
{
public static void main(String[] args)
{
String s1="hi how are you";
s1=s1.replace('a', 'A');
s1 =s1.replace('e', 'E');
s1 =s1.replace('i', 'I');

[Code]...

this is working properly.

but when i trying with Scanner i am facing problem.

public class Demo2
{
public static void main(String[] args)
{
java.util.Scanner scn= new java.util.Scanner(System.in)
String s1=scn.next();
s1=s1.replace('a', 'A');

[Code]...

View Replies View Related

Write A Program To Reverse Each Word In Line (sentence)

Jul 3, 2014

Write a program to reverse each word in line(sentence)?

View Replies View Related

Prompt User For Integer To Make Sure Length Entered By User Is A Power Of 2

Oct 8, 2014

Basically I need to make a program prompts the user for an integer, check to make sure the length entered by the user is a power of 2 and at least 2. Then I need to convert from base e to base 2 then I need to print the tick marks of a ruler based of the value of the length.

I got the whole converting thing working and the check for a power of 2, that wasn't an issue because it didn't require any recursion. I just don't know how to print out the proper tick mark values.

The way it is supposed to work is that it needs to look like this. Say the user enters 8;

012131210
012345678

Or if the user enters 16;

01213121412131210
01234567890123456

The bottom row is pretty much just the index value, that I print fine.

The top row though is supposed to be the length of the ticks on a ruler, with the middle most value being the value of the conversion from base e to base 2 from above. I can get that printed and what I get just looks like this.

For 8;

000030000
012345678

For 16;

00000000400000000
01234567890123456

As you can see I can get the middle value and the index values below but I don't know how to use recursion to get the right numbers.

Here's my current code.

import java.util.*;
public class TickMarks {
public static void main (String args[]){
Scanner input = new Scanner(System.in);
boolean looping = true;
while(looping == true){
System.out.print("Please enter a length: ");

[Code]...

Now the methods isPowerOfTwo() and printLength() both work fine. However, I'm not sure how to get the left and right side working.

My thoughts were to split the length in half and get a left and right side. I gave both of them arrays so I can keep track of the values. Now as you've seen above I get all zeros and I know it's because that's the default value in an array, I just don't know how to get the proper values.

View Replies View Related

How To Make Sure Only One Particular Type Of Instance Is Open At A Time

Feb 23, 2015

This isn't asking to make a Singleton, where I want only one type of a type of window period.

It's not where I want only one instance of the program itself open at a time. It's more along the lines of, though I don't care if there is more than one Microsoft Word open at the same time, I don't want more than one instance of blablabla.docx to be open at once.

In other words, I'd need to scan my system or my list of open windows of a particular type to make sure that no two ones where equals is true will match up.

I was going to do it to associate it with a particular name with a window (it's sort of an addressbook, though not quite.) I'd use a JFrame subclass to make these windows that have a name go with them. For now, unless I find the great need for this project that there might be someone with the exact same name around here, I'm going to use equals() with name on this. I can type cast and whatnot.

However, how do I get to know what windows are open at once so I can check all my list of open windows, and I'd prefer to check only ones of certain types, though I may have to check them all indirectly perhaps, before I check the names.

I'm wondering is it a getChildren() of the main window or something else? How do I know what all of my open windows are?

I'd prefer to have to check as few as possible and not have to check unnecessary ones.

As for the structure of my thing that would click that would open the new window, I'm not sure yet. I'm almost leaning JLabel, though it's a bit less sophisticated, as it might be more difficult to add to a JList (maybe I"m wrong on thinking on that. It's been a little while since I last worked with JLists.)

(I think I can set list data, but the problem is, even using an ArrayList, it only takes an array for this as a param and ArrayList returns an Array of type Object, which means a lot of pesky type casting every time just to add or remove a name.)

It does have Vector, but I thought Vector was being phased out.

Anyway, without having too much code given, as I'm not sure how I'll set this up yet, how do you get access to all of the windows being opened to be able to check them for certain traits?

View Replies View Related

Accepting User Input Of Reference Type

Nov 16, 2014

I have a Homework that's on Polymorphism and inheritance. The problem is of a triangle class. The super class is GeometricObject and the subclass Triangle. I have the parent and child classes compiling, now it's the test program.

The problem is the examples in the book don't show anything about prompting input for objects. The objects in the Triangle class are: side1, side2, and side3 and so I created objects in the test: Triangle sideOne = new Triangle(); . I've tried to compile but jGrasp doesn't like anything I do and the instructor in my class hasn't shown us examples yet. Can I prompt input for reference type and not just primitive type?

View Replies View Related

Java Program That Will Ask A User To Input Grades Until User Inputs Sentinel Value

Apr 9, 2014

Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".

View Replies View Related

Program That Takes User Odd Number And Print Prime Numbers Lower Than User Input

Nov 4, 2014

I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.

public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;

public void getUserNum()

[code]...

View Replies View Related

Servlets :: Cannot Make Static Reference To Non-static Method GetQuery From Type Resource

Mar 26, 2015

This is my code inside the method:

@Post
public static String getDetails(Representation entity) throws Exception {
String customerId = getQuery().getValues("cus_id");
}

I use this code in Restlet Representation. I try to get the value from the Request API. But I am facing the problem as "Cannot make a static reference to the non-static method getQuery() from the type Resource".

View Replies View Related

Swing/AWT/SWT :: How To Make A Grid For Crossword - User Writable

Apr 22, 2015

I've been reading that there's no way of making a JLabel user writable. What can I use inside the grid to make it writable with a keylistener? I'm making a crossword.

View Replies View Related

How To Make Shapes Move At Same Time When User Enter Up

Oct 1, 2014

How to make shapes move at same time when user enter up it should move up. It works for rectangle but i don't know how to move the others like that. (btw i am new to java). How can i do that?

import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
import java.awt.geom.Ellipse2D;

[Code] .....

View Replies View Related

How To Make Button Clear The Data That User Entered

Mar 25, 2015

package com.example.imc;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

[Code] ....

View Replies View Related

User Input 3 Sides - Output Invalid If Does Not Make A Triangle

Nov 4, 2014

I had to make a program that allows the user to enter 3 sides and it should output "invalid" if it does not make a triangle and if it does make a triangle it calculates the area of the triangle and it doesnt seem to do anything but say "invalid" as the out put.

import java.util.Scanner;
public class MyTriangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean valid = true;
double side1, side2, side3, area, A;
 
[Code] ....

View Replies View Related

Cannot Make Static Reference To Non-static Type String

Apr 27, 2014

I am writing the following program in Java SE 7. It throwing "Cannot make a static reference to the non-static type String" . However if I write parameterised String inside main method as  java.lang.String[] args, it compiles fine.
 
class MainClass<String> {
  <T> MainClass(T t) {
   System.out.println(t.getClass().getName());
  } 
  public static void main(String[] args) {
  System.out.println("asdasd");
   new MainClass<>("");
  }
}
 
I mean following programs compile fine in Java SE 7 :
 
class MainClass<String> {
  <T> MainClass(T t) {
   System.out.println(t.getClass().getName());
  }
  public static void main(java.lang.String[] args) {
  System.out.println("asdasd");
   new MainClass<>("");
  }
}

View Replies View Related

Rounding Integer Type In Program

Mar 8, 2014

I have this code line:

String sectionText = String.valueOf((int)percents.getYellowPercent());

And I want the integer value to be displayed, instead of double. This works, but when the program rounds the double into integer, if the number is for example 75,56 (this is %) or 3,5 I would like it to be rounded in 76 (or 3,6 for the other example) since as it is at this moment, when all the calculated integers are summed, the result is not 100%, but 99%.

View Replies View Related

Using Boolean Data Type In Program

Sep 25, 2014

While practicing java i have came across boolean data type. i have executed below program but i am not sure how i got output of the program like below:

10 > 9 is true

Here is my program:

class BoolTest3
{
public static void main(String args[])
{
System.out.println("10 > 9 is "+(10>9));
}
}

My question is: how this program will come to know that 10>9 true or false.. how bolean data type used in this program.

View Replies View Related

Make A Program With Two Buttons

Feb 10, 2014

I'm trying to make a program with two buttons... when you click the first a label shows a red square when you click the second it shows a green square... right now i have the imageicons as a comment because when they weren't a comment and i ran the program i saw nothing... the same thing happens when i add label2 to panel3.

Java Code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GUI3{
public static void main(String[] args){
//frame
JFrame frame = new JFrame("Test");

[code]...

View Replies View Related

Invalid Type And Syntax Error For Translator Program

Apr 5, 2015

Getting the following error at line 13.

Multiple markers at this line - void is an invalid type for the variable loadDictionaryFromFile - Syntax error on token ")", ; expected - Syntax error on token "(", ; expected

Line 13 starts public void load....

Code:

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class PirateTranslator
{
public static void main(String[] args)

[Code] .....

View Replies View Related

How To Make A Program Run Multiple Times

May 18, 2014

I have made a basic math game that asks you questions and tells you if you have answered them correctly or incorrectly. The game runs great! The thing is that it asks you a question one time and after you answer you have to run the program again. I want to get the program to ask ten questions. After that I want to figure out a scoring system for it but the first step is to get it to ask my ten questions. Here is my code.

package pkgnew;
import java.util.Scanner;
import java.util.Random;
public class New {
public static void main(String args[]) {

[Code] .....

View Replies View Related

Stars Program - How To Make Hourglass

Apr 30, 2015

I just recently started programming and came across the star patterns which normally I am able to do extremely quickly except with this one. I am trying to make a hourglass but I seem to only be able to make the top of it. How to do the opposite so I can finish the hourglass.

package hourglass;
class Hourglass {
public static void main (String[] arguments){
for(int j=1;j<=5;j++) {
for(int i=1;i<=j;i++)

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved