Exercise 1
• Examine ShoppingCart.java.
– Perform the following:
– Use the indexOf method to get the index for the space character (" ") within custName. Assign it to spaceIdx.
– Use the substring method and spaceIdx to get the first name portion of custName. Assign it to firstName and print firstName.
public class ShoppingCart {
public static void main (String[] args){
String custName = "Steve Smith";
String firstName;
int spaceIdx;
// Get the index of the space character (" ") in custName.
// Use the substring method parse out the first name and print it.
}
}
Exercise 2
Examine NameMaker.java.
• Perform the following:
– Declare String variables: firstName, middleName, lastName, and fullName
– Prompt users to enter their first, middle, and last names and read the names from the keyboard.
– Set and display the fullName as firstName+a blank char+middleName+a blank char+lastName.
package com.example;
public class NameMaker {
public static void main(String args[])
{
}
Exercise 1 • Examine ShoppingCart.java. – Perform the following: – Use the indexOf method to get...
Java Homework Problems: 4. • Examine AddImport.java. – Perform the following: – Replace the fully qualified name to access the Jlabel component with an import statement. – To import classes from the util package, replace multiple import statements with a single import statement. /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.Calendar; import java.util.Date; public...
JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you created in the previous lab. In this lab, create a Student class with the following class variable: Student name: Name (Note: Name is a datatype) Student Id: String Create the getter and setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Complete...
read the code and comments, and fix the program by INSERTING the missing code in Java THank you please import java.util.Scanner; public class ExtractNames { // Extract (and print to standard output) the first and last names in "Last, First" (read from standard input). public static void main(String[] args) { // Set up a Scanner object for reading input from the user (keyboard). Scanner scan = new Scanner (System.in); // Read a full name from the user as "Last, First"....
Task #3 Working with Strings 1. Use the charAt method to get the first character in firstName and store it in a variable called firstInitial. 2. Print out the user’s first initial. 3. Use the toUpperCase method to change the fullName to upper and store it back into the fullName variable. 4. Add a line that prints out tha value of fullName and how many characters are in the string stored in fullName java
Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is: Maya Jones Jones, Maya import java.util.Scanner; public class SpaceReplace { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); String firstName; String lastName; //answer goes here// } }
I have currently a functional Java progam with a gui. Its a
simple table of contacts with 3 buttons: add, remove, and edit.
Right now the buttons are in the program but they do not work yet.
I need the buttons to actually be able to add, remove, or edit
things on the table. Thanks so much.
Here is the working code so far:
//PersonTableModel.java
import java.util.List;
import javax.swing.table.AbstractTableModel;
public class PersonTableModel extends AbstractTableModel
{
private static final int...
Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...
java 1. Write a method header on line three with the following specs: Returns: a boolean Name: beTrue Parameters: none public class Main { { return true; } } 2. Write a method header on line two with the following specs: Returns: a String Name: makeCapital Parameters: a String named "name" You should not be writing code on any line other than #2 public class Main { { String ans = name.toUpperCase();...
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...
Debug following methods(longestRun(finds how many times a character got repeated), findLastP(finds last p in a string), findFirstP(finds first p in a string)) in java language. public class simpleLoops { /** * @param args */ public static void main(String[] args) { System.out.println(longestRun("aabbbccd")); System.out.println("Expected 3"); System.out.println(longestRun("aaa")); System.out.println("Expected 3"); System.out.println(longestRun("aabbbb")); System.out.println("Expected 4"); int count = countP("Mississippi"); System.out.println(count); int result = findLastP("Mississippi"); System.out.println(result); result = findFirstP("stop"); System.out.println(result); result = findFirstP("xxxyyyzzz"); System.out.println(result); } /** *...