Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Answer to problem 64:
- package com.company;
- public class Point
- {
- private int x;
- private int y;
- public Point() //Default constructor
- {
- x=0;
- y=0;
- }
- public Point(int x1, int y1) //Default constructor
- {
- x = x1;
- y = y1;
- }
- public void setX(int x1)
- {
- x = x1;
- }
- public void setY(int y1)
- {
- y = y1;
- }
- public int getX()
- {
- return x;
- }
- public int getY()
- {
- return y;
- }
- public void PrintPoint()
- {
- System.out.println("Point p1 = ("+x+","+y+")");
- }
- public double DistanceToOrigin()
- {
- return (Math.sqrt(x*x+y*y));
- }
- public void translatePoint(int dx, int dy)
- {
- x = x + dx;
- y = y + dy;
- }
- }
- package com.company;
- import java.text.DecimalFormat;
- public class ClientPoint {
- public static void main (String[] args){
- Point p1 = new Point();
- Point p2 = new Point();
- DecimalFormat distanceFormat = new DecimalFormat("#0.00");
- System.out.println(" The distance is "+distanceFormat.format(p2.DistanceToOrigin()));
- p1.PrintPoint();
- double distance = p1.DistanceToOrigin();
- System.out.println(distance);
- p2.setX(-3);
- Point p3 = new Point();
- p3.setX(p2.getX()); // set value of p3 to p2.
- p3.translatePoint(3,4);
- p3.PrintPoint();
- }
- }
- Answer to problem 67.
- package com.company;
- /*
- Arush Adabala
- 1/15/2019
- Reads and states sentence types
- */
- import java.util.*;
- import java.lang.*;
- public class Decrypter {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Please type a string with nine characters or more below");
- String sentence = input.next();
- char character1 = sentence.charAt(0); // reads first char
- char character2 = sentence.charAt(2); // reads third char
- char character3 = sentence.charAt(4); // reads fifth char
- char character4 = sentence.charAt(6); // reads seventh char
- char character5 = sentence.charAt(8); // reads ninth char
- int stringlength = sentence.length();
- if(stringlength>=9){
- System.out.println(character1+character2+character3+character4+character5);
- }
- else{
- System.out.println("invalid input.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement