SlideShare ist ein Scribd-Unternehmen logo
1 von 10
COSC 1436 Java programming
FOR MORE CLASSES VISIT
tutorialoutletdotcom
NameFirstNamePhoneNumberTranslator.java
Coin.java
LastNameFirstNameCoinDriver.java
ModifiedCoin.java Note 1: Unless otherwise mentioned, you are asked
to upload ONLY your java source files through
blackboard. Email submission is not accepted, because of confusion in
grading.
Note 2: If your programs contain any syntactical errors, no points will be
given. Thus, please make sure your
programs are properly compiled with computers at the CS labs, not only
in your laptop or desktop
environments.
Note 3: No late submission will be accepted, thus keep the deadline.
Note 4: Grading will be divided into two categories, formatting and
logic, where formatting compromise
25% of your total grade. Formatting will be based on the following
rules. Rule 1: Naming is an important issue in Java. Not only you should
you define meaningful variable names,
but should also give appropriate names for the physical java file, which
must be the same as the public class
name that you edit.
Unless otherwise mentioned, you will follow the industry standard for
Java naming convention:
(1) Java Classes start in uppercase and each individual word in the class
name is capitalized;
(2) All Java methods and variables start in lowercase and each individual
word in the method and
variable is capitalized;
(3) Each final variable (known as a constant) should be written in all
uppercase.
Rule 2: There should be a space around all operators (e.g., 3 + 5, not
3+5). In addition, spacing with regards
to parentheses should be consistent.
Dr. An, Mrs. Varol & Dr. Rabieh: COSC 1436 Assignment #3 –
Spring 2017 Page 2 of 6
Rule 3: In addition to the Java naming conventions, you are asked to add
your name in front of each class
name like LastNameFirstNameClassName.java.
For instance, if your name is “John Doe” and the class name is
“RightTriangle”, then the class name in your
source code should be “DoeJohnRightTriangle” and your corresponding
physical file name should be
“DoeJohnRightTriangle.java”.
Rule 4: Everything nested inside of an open brace should be indented
with regular-sized spaces (say, 4 or 8
spaces). The open brace for functions and classes should (1) come at the
end of the line and be preceded by a
space like
public class DoeJohnRightTriangle {
public static void main( String args ) {
}
} or (2) start with the new line as shown below:
public class DoeJohnRightTriangle
{
public static void main( String args )
{
}
} Rule 5: Always type block Javadoc comments to include title of the
project, program’s purpose, your name,
the date, and the version number as in the lectures or in the labs. For
example,
/*********************************************************
**********
@Title:
LastNameFirstNameClassName
@Purpose:
To verify the edit, compile, execute function in Textpad
@Author:
(your last & first name)
@Date:
(today’s date)
@Version:
1.0
**********************************************************
**********/ Dr. An, Mrs. Varol & Dr. Rabieh: COSC 1436
Assignment #3 – Spring 2017 Page 3 of 6 Question 1 (50 points):
Reading and Writing to file
Write a program that
(1) reads alphabetic phone numbers from the text file,
“AlphabeticPhoneNumbers.txt”,
(2) translates each of the alphabetic phone numbers to the equivalent
numeric phone number, and
(3) writes the translated numeric numbers into a text file,
“NumericPhoneNumbers.txt”.
(4) uses Javadoc comments to comment every method you write, use
@params and @return tags to write
comments about the parameters and return types of methods
For example, when the program reads 555-GET-FOOD, it should write
555-438-3663 into
NumericPhoneNumbers.txt.
On a standard telephone, the alphabetic letters are mapped to numbers in
the following fashion;
A, B and C = 2
D, E, and F = 3
G, H, and I = 4
J, K, and L = 5
M, N, and O = 6
P, Q, R, and S = 7
T, U, and V = 8
W, X, Y, and Z = 9
You need to break your code into following methods: getFile: It opens
the AlphabeticPhoneNumbers.txt file, and reads each line (a phone
number) as a
String from the file. It calls isValid method for validity check of the
phone number read. If isValid
method returns true, then it calls getPhoneNumber method for
translation. isValid: It returns true if the alphabetical phone number:
(1) includes letters, numbers or dashes, and
(2) its length is 12 , 13 or 14 (with country code).
Otherwise, it returns false. getPhoneNumber: It accepts one argument
that is the alphabetical phone number passed from
getFile mehod, translates it to the equivalent numeric phone number, and
writes the result in
NumericPhoneNumbers.txt file.
Here are the necessary steps:
A. getFile method needs to
1. create object(s) of file input/output related classes to open the text file
(AlphabeticPhoneNumber.txt)
2. create an object of Scanner class to read data from the text file
3. declare any necessary variables that will be used in the code
4. read each line from the text file until no more line is left. (Hint: Recall
hasNext() method). (a loop is needed!)
a. read each line (an alphabetical phone number) as a String
b. call isValid method to check if the alphabetical phone number is
valid or not. If yes, call getPhoneNumber method by passing the
phone number, otherwise read the next line.
* Don’t forget to handle exceptions. Recall throws IOException
B. getPhoneNumber method needs to Dr. An, Mrs. Varol & Dr.
Rabieh: COSC 1436 Assignment #3 – Spring 2017 Page 4 of 6
1. accept a String data (an alphabetical phone number) as its argument
2. have a loop to access each character of the String and do the
followings
until we reach the end of the String:
a. access each character in that String by specifying index number
-> charAt(i)
b. check whether the character is a digit, letter or a special
character.
* Hint: import java.lang.Character =>
In order to test if a character is a letter or digit, you
should use isLetterOrDigit() method that is provided in
Character wrapper class, also Character wrapper class has other
methods such as isLetter, isDigit, etc. or remember Unicode that
provides a unique number for every character.
c. If it is a letter, convert it into the corresponding digit (see
the map for it above).
* Don’t forget to handle exceptions. Recall throws IOException.
3. create necessary objects of file input/output related classes to open the
text file, and to write the translated numerical phone number.
C. isValid method needs to
1. check each alphabetical phone number for validity, and if it is valid,
return true, otherwise return false. the alphabetical phone number is
valid if it includes:
a. letters, numbers or dashes, and
b. its length (the number of characters in the phone number read) is
12 or 14 (with country code)
D. Close the text files. Hint: Your program should display the result as
shown in below
1-800-FLOWERS = 1-800-3569377
1-800-GOT-JUNK = 1-800-468-5865
555-GET-FOOD = 555-438-3663
1-800-PET-MEDS = 1-800-738-6337
1-800-LAWYERS = 1-800-5299377
1-800-GO-FONTS = 1-800-46-36687
713-333-MOVE = 713-333-6683
Grading criteria include documentation, descriptive variable names, and
adherence to the coding convention
noted on pages 1 & 2.
Your file will have the following documentation header:
Your file will have the header and the class definition as follows:
/*********************************************************
**********
@Title:
LastNamePhoneNumberTranslator
@Purpose:
To get familiar with input/output classes, String object, and various
operations in Java
@Author:
(your last first name)
@Date:
(today’s date)
@Version:
1.0
**********************************************************
***********/ Dr. An, Mrs. Varol & Dr. Rabieh: COSC 1436
Assignment #3 – Spring 2017 Page 5 of 6 Question 2 (30 points): Coin
Toss Class
Write a class named Coin. The Coin class should have the following
field and methods:
Coin
- sideUp : String
+ Coin()
+ toss(): void
+ getSideUp(): String The sideUP field will hold either “heads” or
“tails” indicating the side of the coin that is facing up.
The constructor randomly determines the side of the coin that is facing
up (“heads” or “tails”) and
initialized the sideUP field accordingly.
The toss method simulates the tossing of the coin. When the toss method
is called, it randomly
determines the side of the coin that is facing up and sets the sideUP field
accordingly.
The getSideUp method returns the value of the sideUp field. Write a
program (driver class) that demonstrates the Coin class. The program
should create an instance of
the class and display the side that is initially facing up. Then, use a loop
to toss the coin 40 times. Each time
the coin is tossed, display the side that is facing up. The program should
keep count of the number of time
heads is facing up and the number of times tails is facing up, and display
those values after the loop finishes. Your file will have the following
documentation comments before the class header:
/**
@Title:
@Purpose:
@Author:
@Date:
@Version:
*/ Coin
To practice random class and objects.
(your last first name)
(today’s date)
1.0 /**
@Title:
@Purpose:
@Author:
@Date:
@Version:
*/ LastNameFirstNameCoinDriver
To practice random class and objects.
(your last first name)
(today’s date)
1.0 Question 3 (20 points): Coin Toss Class with multiple constructors
and methods
overloading
Write a program that demonstrate a modified version of the Coin class.
Your class should have the name
ModifiedCoin. The ModifiedCoin class should have two constructors
with zero arguments; the default
constructor and a constructor that takes the sideUp as an argument. The
ModifiedCoin should have two
versions of toss method. The first version takes zero arguments and sets
the sideUP field randomly (a fair
Dr. An, Mrs. Varol & Dr. Rabieh: COSC 1436 Assignment #3 –
Spring 2017 Page 6 of 6
toss). The second version of the toss method takes a String argument that
can be either head or tail and
returns the same String (unfair toss).
Write a program that create two instances (objects) of the ModifiedCoin
class using the two different
constructors and displays the side that is initially facing up. Call the two
versions of the toss method and
display the side that is facing up.
Your file will have the following documentation comments before the
class header:
/**
@Title:
@Purpose:
@Author:
@Date:
@Version:
*/ ModifiedCoin
To practice Method overloading and class with multiple constructors.
(your last first name)
(today’s date)
/**
@Title: Coin
@Purpose: To practice random class and objects.
@Author: (Martinez, James)
@Date: (03/20/2017)
@Version: 1.0
*/
import java.util.*;
public class Coin
{
private String sideUp;
//*will call my toss method*/
public Coin()
{
toss();
}
/*this method will determine whether or not the coin is heads or tails*/
public void toss()
{
Random myRand = new Random();
int face = myRand.nextInt(2);
if(face == 0)
{
sideUp = "heads";
}
else
{
sideUp = "tails";
}
}
/*this method should return the number of heads and tails that result
from my
coin toss*/
public String getSideUp()
{
return sideUp;
}
}
/**
@Title: MartinezJamesCoinDriver
@Purpose: To practice random class and objects.
@Author: (Martinez, James)
@Date: (03/20/2017)
@Version: 1.0
*/
public class CoinDriver
{
public static void main(String args)
{
Coin coin = new Coin();
int headsSum = 0;
int tailsSum = 0;
/*This for loop will simulate the coin being tossed*/
for(int i = 1; i <= 40; i++)
{
coin.toss();
System.out.println(coin.getSideUp());
if(coin.getSideUp().equals("heads"))
{
headsSum++;
}
else if(coin.getSideUp().equals("tails"))
{
tailsSum++;
} }
System.out.println("Total number of heads: " + headsSum +
"nTotal number of
tails: " + tailsSum);
}
}
***************************************************

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Handout#04
Handout#04Handout#04
Handout#04
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
 
Assignment11
Assignment11Assignment11
Assignment11
 
Structures-2
Structures-2Structures-2
Structures-2
 
Assignment1
Assignment1Assignment1
Assignment1
 
Handout#03
Handout#03Handout#03
Handout#03
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
 
Python Interview questions 2020
Python Interview questions 2020Python Interview questions 2020
Python Interview questions 2020
 
Data file handling
Data file handlingData file handling
Data file handling
 
Handout#09
Handout#09Handout#09
Handout#09
 
Unit 1 question and answer
Unit 1 question and answerUnit 1 question and answer
Unit 1 question and answer
 
Comp 122 lab 7 lab report and source code
Comp 122 lab 7 lab report and source codeComp 122 lab 7 lab report and source code
Comp 122 lab 7 lab report and source code
 
Coursebreakup
CoursebreakupCoursebreakup
Coursebreakup
 
Oops
OopsOops
Oops
 
Handout#10
Handout#10Handout#10
Handout#10
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
 
Handout#02
Handout#02Handout#02
Handout#02
 
Handout#07
Handout#07Handout#07
Handout#07
 

Ähnlich wie Cosc 1436 java programming/tutorialoutlet

Android coding standard
Android coding standard Android coding standard
Android coding standard Rakesh Jha
 
CSE 1310 – Spring 21Introduction to ProgrammingLab 4 Arrays and Func
CSE 1310 – Spring 21Introduction to ProgrammingLab 4 Arrays and FuncCSE 1310 – Spring 21Introduction to ProgrammingLab 4 Arrays and Func
CSE 1310 – Spring 21Introduction to ProgrammingLab 4 Arrays and FuncMargenePurnell14
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
The Lab assignment will be graded out of 100 points.  There are .docx
The Lab assignment will be graded out of 100 points.  There are .docxThe Lab assignment will be graded out of 100 points.  There are .docx
The Lab assignment will be graded out of 100 points.  There are .docxjmindy
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocksİbrahim Kürce
 
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdfTask #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdfinfo706022
 
Cmps 260, fall 2021 programming assignment #3 (125 points)
Cmps 260, fall 2021 programming assignment #3 (125 points)Cmps 260, fall 2021 programming assignment #3 (125 points)
Cmps 260, fall 2021 programming assignment #3 (125 points)mehek4
 
C programming assignment presentation file
C programming assignment presentation fileC programming assignment presentation file
C programming assignment presentation filesantoshkumarhpu
 
Mca1020 programming in c
Mca1020  programming in cMca1020  programming in c
Mca1020 programming in csmumbahelp
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answersdebarghyamukherjee60
 
Java Basics.pdf
Java Basics.pdfJava Basics.pdf
Java Basics.pdfEdFeranil
 
Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingHamad Odhabi
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02auswhit
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsjody zoll
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxfredharris32
 

Ähnlich wie Cosc 1436 java programming/tutorialoutlet (20)

Android coding standard
Android coding standard Android coding standard
Android coding standard
 
CSE 1310 – Spring 21Introduction to ProgrammingLab 4 Arrays and Func
CSE 1310 – Spring 21Introduction to ProgrammingLab 4 Arrays and FuncCSE 1310 – Spring 21Introduction to ProgrammingLab 4 Arrays and Func
CSE 1310 – Spring 21Introduction to ProgrammingLab 4 Arrays and Func
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
Class 8 - Java.pptx
Class 8 - Java.pptxClass 8 - Java.pptx
Class 8 - Java.pptx
 
The Lab assignment will be graded out of 100 points.  There are .docx
The Lab assignment will be graded out of 100 points.  There are .docxThe Lab assignment will be graded out of 100 points.  There are .docx
The Lab assignment will be graded out of 100 points.  There are .docx
 
Java execise
Java execiseJava execise
Java execise
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
 
Assignment 2
Assignment 2Assignment 2
Assignment 2
 
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdfTask #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
 
Cmps 260, fall 2021 programming assignment #3 (125 points)
Cmps 260, fall 2021 programming assignment #3 (125 points)Cmps 260, fall 2021 programming assignment #3 (125 points)
Cmps 260, fall 2021 programming assignment #3 (125 points)
 
C programming assignment presentation file
C programming assignment presentation fileC programming assignment presentation file
C programming assignment presentation file
 
Mca1020 programming in c
Mca1020  programming in cMca1020  programming in c
Mca1020 programming in c
 
java intro.pptx.pdf
java intro.pptx.pdfjava intro.pptx.pdf
java intro.pptx.pdf
 
PHP Reviewer
PHP ReviewerPHP Reviewer
PHP Reviewer
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answers
 
Java Basics.pdf
Java Basics.pdfJava Basics.pdf
Java Basics.pdf
 
Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programming
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docx
 

Kürzlich hochgeladen

week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 

Kürzlich hochgeladen (20)

week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 

Cosc 1436 java programming/tutorialoutlet

  • 1. COSC 1436 Java programming FOR MORE CLASSES VISIT tutorialoutletdotcom NameFirstNamePhoneNumberTranslator.java Coin.java LastNameFirstNameCoinDriver.java ModifiedCoin.java Note 1: Unless otherwise mentioned, you are asked to upload ONLY your java source files through blackboard. Email submission is not accepted, because of confusion in grading. Note 2: If your programs contain any syntactical errors, no points will be given. Thus, please make sure your programs are properly compiled with computers at the CS labs, not only in your laptop or desktop environments. Note 3: No late submission will be accepted, thus keep the deadline. Note 4: Grading will be divided into two categories, formatting and logic, where formatting compromise 25% of your total grade. Formatting will be based on the following rules. Rule 1: Naming is an important issue in Java. Not only you should you define meaningful variable names, but should also give appropriate names for the physical java file, which must be the same as the public class name that you edit. Unless otherwise mentioned, you will follow the industry standard for Java naming convention: (1) Java Classes start in uppercase and each individual word in the class name is capitalized; (2) All Java methods and variables start in lowercase and each individual
  • 2. word in the method and variable is capitalized; (3) Each final variable (known as a constant) should be written in all uppercase. Rule 2: There should be a space around all operators (e.g., 3 + 5, not 3+5). In addition, spacing with regards to parentheses should be consistent. Dr. An, Mrs. Varol & Dr. Rabieh: COSC 1436 Assignment #3 – Spring 2017 Page 2 of 6 Rule 3: In addition to the Java naming conventions, you are asked to add your name in front of each class name like LastNameFirstNameClassName.java. For instance, if your name is “John Doe” and the class name is “RightTriangle”, then the class name in your source code should be “DoeJohnRightTriangle” and your corresponding physical file name should be “DoeJohnRightTriangle.java”. Rule 4: Everything nested inside of an open brace should be indented with regular-sized spaces (say, 4 or 8 spaces). The open brace for functions and classes should (1) come at the end of the line and be preceded by a space like public class DoeJohnRightTriangle { public static void main( String args ) { } } or (2) start with the new line as shown below: public class DoeJohnRightTriangle { public static void main( String args ) { } } Rule 5: Always type block Javadoc comments to include title of the project, program’s purpose, your name, the date, and the version number as in the lectures or in the labs. For example,
  • 3. /********************************************************* ********** @Title: LastNameFirstNameClassName @Purpose: To verify the edit, compile, execute function in Textpad @Author: (your last & first name) @Date: (today’s date) @Version: 1.0 ********************************************************** **********/ Dr. An, Mrs. Varol & Dr. Rabieh: COSC 1436 Assignment #3 – Spring 2017 Page 3 of 6 Question 1 (50 points): Reading and Writing to file Write a program that (1) reads alphabetic phone numbers from the text file, “AlphabeticPhoneNumbers.txt”, (2) translates each of the alphabetic phone numbers to the equivalent numeric phone number, and (3) writes the translated numeric numbers into a text file, “NumericPhoneNumbers.txt”. (4) uses Javadoc comments to comment every method you write, use @params and @return tags to write comments about the parameters and return types of methods For example, when the program reads 555-GET-FOOD, it should write 555-438-3663 into NumericPhoneNumbers.txt. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion; A, B and C = 2 D, E, and F = 3 G, H, and I = 4 J, K, and L = 5
  • 4. M, N, and O = 6 P, Q, R, and S = 7 T, U, and V = 8 W, X, Y, and Z = 9 You need to break your code into following methods: getFile: It opens the AlphabeticPhoneNumbers.txt file, and reads each line (a phone number) as a String from the file. It calls isValid method for validity check of the phone number read. If isValid method returns true, then it calls getPhoneNumber method for translation. isValid: It returns true if the alphabetical phone number: (1) includes letters, numbers or dashes, and (2) its length is 12 , 13 or 14 (with country code). Otherwise, it returns false. getPhoneNumber: It accepts one argument that is the alphabetical phone number passed from getFile mehod, translates it to the equivalent numeric phone number, and writes the result in NumericPhoneNumbers.txt file. Here are the necessary steps: A. getFile method needs to 1. create object(s) of file input/output related classes to open the text file (AlphabeticPhoneNumber.txt) 2. create an object of Scanner class to read data from the text file 3. declare any necessary variables that will be used in the code 4. read each line from the text file until no more line is left. (Hint: Recall hasNext() method). (a loop is needed!) a. read each line (an alphabetical phone number) as a String b. call isValid method to check if the alphabetical phone number is valid or not. If yes, call getPhoneNumber method by passing the phone number, otherwise read the next line. * Don’t forget to handle exceptions. Recall throws IOException B. getPhoneNumber method needs to Dr. An, Mrs. Varol & Dr. Rabieh: COSC 1436 Assignment #3 – Spring 2017 Page 4 of 6 1. accept a String data (an alphabetical phone number) as its argument 2. have a loop to access each character of the String and do the
  • 5. followings until we reach the end of the String: a. access each character in that String by specifying index number -> charAt(i) b. check whether the character is a digit, letter or a special character. * Hint: import java.lang.Character => In order to test if a character is a letter or digit, you should use isLetterOrDigit() method that is provided in Character wrapper class, also Character wrapper class has other methods such as isLetter, isDigit, etc. or remember Unicode that provides a unique number for every character. c. If it is a letter, convert it into the corresponding digit (see the map for it above). * Don’t forget to handle exceptions. Recall throws IOException. 3. create necessary objects of file input/output related classes to open the text file, and to write the translated numerical phone number. C. isValid method needs to 1. check each alphabetical phone number for validity, and if it is valid, return true, otherwise return false. the alphabetical phone number is valid if it includes: a. letters, numbers or dashes, and b. its length (the number of characters in the phone number read) is 12 or 14 (with country code) D. Close the text files. Hint: Your program should display the result as shown in below 1-800-FLOWERS = 1-800-3569377 1-800-GOT-JUNK = 1-800-468-5865 555-GET-FOOD = 555-438-3663 1-800-PET-MEDS = 1-800-738-6337 1-800-LAWYERS = 1-800-5299377 1-800-GO-FONTS = 1-800-46-36687 713-333-MOVE = 713-333-6683 Grading criteria include documentation, descriptive variable names, and adherence to the coding convention
  • 6. noted on pages 1 & 2. Your file will have the following documentation header: Your file will have the header and the class definition as follows: /********************************************************* ********** @Title: LastNamePhoneNumberTranslator @Purpose: To get familiar with input/output classes, String object, and various operations in Java @Author: (your last first name) @Date: (today’s date) @Version: 1.0 ********************************************************** ***********/ Dr. An, Mrs. Varol & Dr. Rabieh: COSC 1436 Assignment #3 – Spring 2017 Page 5 of 6 Question 2 (30 points): Coin Toss Class Write a class named Coin. The Coin class should have the following field and methods: Coin - sideUp : String + Coin() + toss(): void + getSideUp(): String The sideUP field will hold either “heads” or “tails” indicating the side of the coin that is facing up. The constructor randomly determines the side of the coin that is facing up (“heads” or “tails”) and initialized the sideUP field accordingly. The toss method simulates the tossing of the coin. When the toss method is called, it randomly determines the side of the coin that is facing up and sets the sideUP field accordingly.
  • 7. The getSideUp method returns the value of the sideUp field. Write a program (driver class) that demonstrates the Coin class. The program should create an instance of the class and display the side that is initially facing up. Then, use a loop to toss the coin 40 times. Each time the coin is tossed, display the side that is facing up. The program should keep count of the number of time heads is facing up and the number of times tails is facing up, and display those values after the loop finishes. Your file will have the following documentation comments before the class header: /** @Title: @Purpose: @Author: @Date: @Version: */ Coin To practice random class and objects. (your last first name) (today’s date) 1.0 /** @Title: @Purpose: @Author: @Date: @Version: */ LastNameFirstNameCoinDriver To practice random class and objects. (your last first name) (today’s date) 1.0 Question 3 (20 points): Coin Toss Class with multiple constructors and methods overloading Write a program that demonstrate a modified version of the Coin class. Your class should have the name
  • 8. ModifiedCoin. The ModifiedCoin class should have two constructors with zero arguments; the default constructor and a constructor that takes the sideUp as an argument. The ModifiedCoin should have two versions of toss method. The first version takes zero arguments and sets the sideUP field randomly (a fair Dr. An, Mrs. Varol & Dr. Rabieh: COSC 1436 Assignment #3 – Spring 2017 Page 6 of 6 toss). The second version of the toss method takes a String argument that can be either head or tail and returns the same String (unfair toss). Write a program that create two instances (objects) of the ModifiedCoin class using the two different constructors and displays the side that is initially facing up. Call the two versions of the toss method and display the side that is facing up. Your file will have the following documentation comments before the class header: /** @Title: @Purpose: @Author: @Date: @Version: */ ModifiedCoin To practice Method overloading and class with multiple constructors. (your last first name) (today’s date) /** @Title: Coin @Purpose: To practice random class and objects. @Author: (Martinez, James) @Date: (03/20/2017) @Version: 1.0
  • 9. */ import java.util.*; public class Coin { private String sideUp; //*will call my toss method*/ public Coin() { toss(); } /*this method will determine whether or not the coin is heads or tails*/ public void toss() { Random myRand = new Random(); int face = myRand.nextInt(2); if(face == 0) { sideUp = "heads"; } else { sideUp = "tails"; } } /*this method should return the number of heads and tails that result from my coin toss*/ public String getSideUp() { return sideUp; } } /** @Title: MartinezJamesCoinDriver
  • 10. @Purpose: To practice random class and objects. @Author: (Martinez, James) @Date: (03/20/2017) @Version: 1.0 */ public class CoinDriver { public static void main(String args) { Coin coin = new Coin(); int headsSum = 0; int tailsSum = 0; /*This for loop will simulate the coin being tossed*/ for(int i = 1; i <= 40; i++) { coin.toss(); System.out.println(coin.getSideUp()); if(coin.getSideUp().equals("heads")) { headsSum++; } else if(coin.getSideUp().equals("tails")) { tailsSum++; } } System.out.println("Total number of heads: " + headsSum + "nTotal number of tails: " + tailsSum); } } ***************************************************