Question

Topics: About Java What is a compiler, and what does it do? Characteristics of the languageStrongly...

Topics:

About Java

What is a compiler, and what does it do?

Characteristics of the languageStrongly typed and statically typed

Everything has a data type & data types must be declared

Case sensitive

Object oriented

System.out.print() vs. System.out.println()

How to use the Scanner class to obtain user input

Data typesWhat are they?

Know the basic types like: int, double, boolean, String, etc.

Variables

What is a variable?

Declarations

Initialization

Assignment

Constants

Reserved words like:

What is a reserved word?

Examples: class, if, import, static, void, while, etc.

Comments – what are they and why do we use them?

Strings

String literals

Concatenation

Escape sequences

String methods:

charAt()

equals()

indexOf()

length()

substring()

toLowerCase() & toUpperCase()

Operators

Arithmetic: +, -, *, /, %

Relational: >, >=, <, <=, ==, !=

Boolean: !, &&, ||

Evaluating expressions

Arithmetic

Relational

Boolean

Decision logic structures using if and if/else statements

Be able to read simple code with if statements and evaluate the output

Be able to write simple programs of no more than 10 lines of code.

Looping structures using while, do/while, and for

Be able to read simple code with loops and evaluate the output

Be able to write simple programs of no more than 10 lines of code.

// Some example code that demonstrates many of the topics listed above

import java.util.Scanner;

public class TestCode

{

public static void main(String []args)

{

Scanner in = new Scanner(System.in);

String text = "";

int spaceCount = 0;

int wordCount = 0;

int letterCount = 0;

double averageWordLength = 0.0;

boolean inputIsValid = false;

boolean hasNoSpaces = false;

boolean startsWithSpace = false;

boolean endsWithSpace = false;

final char SPACE = ' ';

do // get a string of words from the user

{

hasNoSpaces = false;

startsWithSpace = false;

endsWithSpace = false;

System.out.print("Enter some words separated by spaces: ");

text = in.nextLine();

// if the text the user enters has no spaces

// then it cannot have more than one word.

if (text.indexOf(SPACE) == -1)

hasNoSpaces = true;

// if the text the user enters starts with a space

// then it is wrong.

if (text.substring(0, 1).equals(" "))

startsWithSpace = true;

// if the text the user enters ends with a space

// then it is wrong.

if (text.substring(text.length() - 1).equals(" "))

endsWithSpace = true;

} while (hasNoSpaces || startsWithSpace || endsWithSpace);

// count the spaces

// by looping through the character in the string index by index

for (int index = 0; index < text.length(); index++)

{

if (text.charAt(index) == SPACE)

spaceCount += 1;

}

// count the words

wordCount = spaceCount + 1; // there will be one more word than spaces

System.out.println("There are " + wordCount + " words in \"" + text + "\"\n");

// find the average word length

letterCount = text.length() - spaceCount;

averageWordLength = (double)letterCount / wordCount; // average letters per word

System.out.println("There average word length is:\t\t" + averageWordLength + "\n");

// get the first word and capitalize it

int indexOfFirstSpace = text.indexOf(SPACE);

String firstWord = text.substring(0, indexOfFirstSpace);

firstWord = firstWord.toUpperCase();

System.out.println("The first word in upper case is:\t" + firstWord + "\n");

// get the last word and capitalize it

int indexOfLastSpace = text.lastIndexOf(SPACE);

String lastWord = text.substring(indexOfLastSpace + 1);

lastWord = lastWord.toUpperCase();

System.out.println("The last word in upper case is:\t\t" + lastWord + "\n");

// which word is longer - the first word or the last word?

if (firstWord.length() > lastWord.length())

{

System.out.printf("\"%s\" is longer than \"%s\".", firstWord, lastWord);

}

else if (firstWord.length() < lastWord.length())

{

System.out.printf("\"%s\" is shorter than \"%s\".", firstWord, lastWord);

}

else

{

System.out.printf("\"%s\" and \"%s\" are the same length.",

   firstWord, lastWord);

}

}

}

You will be given the following information on the exam document:

Quick Reference:

class java.lang.String

char charAt(int index) // Returns the character at the specified index.

int compareTo(String anotherString) // Compares two string lexicographically.

int length( ) //Returns the length of this string.

String substring(int from , int to ) //Returns a new string that is a substring of this string.

String substring(int from) //Returns substring(from, length())

String toLowerCase( )

int indexOf(String s)   // returns the index of the first occurrence of s, returns –1 if not found

class java.util.Scanner

String next() // reads the next string token from the keyboard

String nextLine() // returns all input remaining on the current line as a string

double nextDouble()

int nextInt()

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This question need so many information please ask question in parts. i will answer first few question according to Chegg Rule.

Java is a class based, object oriented, Platform independent, portable, multi threaded, dynamic, distributed and robust interpreted Programming Language.

A compiler is a special program that processes statements written in a particular programming language and turns them into machine language.Java compiler javac compile java source code and red return byte code as .class file.

A statically typed language has a type system that is checked at compile time by the implementation.In a "strongly typed" language, it is not possible for the programmer to work around the restrictions imposed by the type system.

Case sensitive means upper case and lower case is treat as different.Java is case sensitive.

Object oriented means a concept whoch is based on object like java is a Object oriented programming lanuage.

System.out.print() : print output on console at same line

System.out.println():  print output on console and then changed line for next output

Use the Scanner class to obtain user input-

First import Scanner class.

then intantiate it as: Scanner sc = new Scanner(System.in);

then read from console using Scanner object like : String str = sc.next();

Add a comment
Know the answer?
Add Answer to:
Topics: About Java What is a compiler, and what does it do? Characteristics of the languageStrongly...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I've previously completed a Java assignment where I wrote a program that reads a given text...

    I've previously completed a Java assignment where I wrote a program that reads a given text file and creates an index that stores the line numbers for where individual words occur. I've been given a new assignment where I need to modify some of my old code. I need to replace the indexer in my Index class with a NavigableMap<String, Word> and update my Word class with NavigableSet<Integer> lines. The instantiated objects should be TreeMap() and TreeSet(). I have below...

  • The following code uses a Scanner object to read a text file called dogYears.txt. Notice that...

    The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...

  • I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt...

    I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...

  • !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random...

    !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random text with my generateText method, you can move on to the second step. Create a third class called Generator within the cs1410 package. Make class. This class should have a main method that provides a user interface for random text generation. Your interface should work as follows: Main should bring up an input dialog with which the user can enter the desired analysis level...

  • CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...

    CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...

  • You will write three static methods to manipulate an input String in different ways using various...

    You will write three static methods to manipulate an input String in different ways using various String methods. You need to provide the code for each of the three static methods in class StringPlay (requirements for each listed below). You will also change the control statement in the test harness to allow for variations in the sentinel value. You need to modify the loop control condition in Lab09.java so that user inputs of ‘finish’, “FINISH”, “FiniSH”, “fINISH”, etc. will end...

  • Hi I really need help with the methods for this lab for a computer science class....

    Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word The Word class represents a single word. It is immutable. You have been provided...

  • 1. What is the height of a full binary search tree that contains 63 nodes 2....

    1. What is the height of a full binary search tree that contains 63 nodes 2. What is the output of this code? Describe what this recursive code does. public class Driver {    public static void main (String[ ] args)   {        String text = “what do I do”;        System.out.println(Mystery.task(text));   } } public class Mystery {    public static int task(String exp)   {         if(exp.equals(“”)           return 0;        else           return 1 + task(exp.substring(1));    } } //from the Java 7 API documentation: public String substring(int...

  • /** * * Jumping frog game: user enters road length and series of jumps and *...

    /** * * Jumping frog game: user enters road length and series of jumps and * the program displays the current position of the frog. */ public class hw4_task5 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int playAgain = 1; int roadLen; System.out.println("JUMPING FROG"); while (playAgain == 1){ System.out.printf("Enter the length of the road: "); roadLen = in.nextInt(); play(roadLen); // Starts a new game with a road this long. System.out.printf("\nDo you want to play again...

  • Please help me do the java project For this project you will be reading in a...

    Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID              Name                              Age                    IsMale           GPA 1                Tom Ryan                       22                       True              3.1 2                Jack Peterson                31                       True              2.7 3                Cindy LuWho                12                       False             3.9 When you read in the header line, you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT